I\'m having issues with accessing files i upload w/ golang. I\'m really new to the language and have gone through more than a few attempts-- can\'t find any answers to this onli
If you know they key of the file upload you can make it a bit simpler I think (this is not tested):
infile, header, err := r.FormFile("file")
if err != nil {
http.Error(w, "Error parsing uploaded file: "+err.Error(), http.StatusBadRequest)
return
}
// THIS IS VERY INSECURE! DO NOT DO THIS!
outfile, err := os.Create("./uploaded/" + header.Filename)
if err != nil {
http.Error(w, "Error saving file: "+err.Error(), http.StatusBadRequest)
return
}
_, err = io.Copy(outfile, infile)
if err != nil {
http.Error(w, "Error saving file: "+err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintln(w, "Ok")