This is my first time using Os.Open and I was wondering can I use that for dynamic images (Images found in different directories) or do I have to put the full path every single time ? For instance in my FormFile
func ExampleFunc(w http.ResponseWriter, t *http.Request) {
t.ParseForm()
f, h, err := t.FormFile("file")
if err != nil {
print(err) }
os.Open(h.Filename)
}
The function above gives me an error no such file or directory found however if I put the full path in there such as
os.Open("/Home/myfiles/Documents/pictures/horse_riding.png")
Then the image opens, is there a way of dynamically get the Image path and inserting that in os.Open ? I do have a FormFile that gets information about the incoming file but not the full path .
In a file server (such as this one), you are suppose to concatenate a root_folder
to the file/path you get from your form.
filepath := path.Join((root_folder), h.Filename)
That way, you open files which are within a certain root folder, instead of any file on your system (which is not secure at all).