Hi,
I have to post a file via an http post request and save it on a folder called public/file
, here is my code :
file, handler, err := r.FormFile("file")
defer file.Close()
if err != nil {
panic(err)
}
f, err := os.OpenFile("./public/file/"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
defer f.Close()
io.Copy(f, file)
The code works if the directory is already created but I want it to create the directory if it isn’t exist…
Do you have an idea about how to do this ?