I have successfully been able to upload images to my ImageStore account however I have had to hardcode each file path . My issue is that my images reside outside of my GoPath are there any way that I can get the actual directory to my images without hardcoding it ? For instance
GoPath = "/Users/IH/Documents/go"
Actual Image Path = "/Users/IH/Documents/pictures/horse_PNG2538.png"
Path I'm getting = "/Users/IH/Documents/go/src"
I need to get the correct path of an image because user's will be able to Upload their images and obviously they are all going to have different paths to their images . This is the code I have
myfile, handler, err := r.FormFile("uploadImage")
if err != nil {
fmt.Println(err)
return
}
defer myfile.Close()
pwd, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(pwd)
file,err := os.Open(pwd + handler.Filename)
defer file.Close()
if err != nil {
fmt.Printf("err opening file: %s", err)
}
The pwd gives me the path /Users/IH/Documents/go/src which offcourse gives me an error because the image is not found there . If I for instance hard code the correct image address then it uploads such as
file,err := os.Open("/Users/IH/Documents/pictures/horse_PNG2538.png")
then the image gets uploaded . Again this image is coming from this directory /Users/IH/Documents/pictures/ how can I spot that directory on image upload without hardcoding it ? any suggestions would be great