Hello everyone, I started quite recently with Go and I’m already a huge fan.
But I am currently working on an WebApplication, where users should be able to upload PDF files and these can be opened through the browser (PDF viewer).
My problem:
If I try to use ioutil.TempFile() the file is damaged and I cannnot open it through the browser and with my locally installed pdf reader. If I try to catch the file, use ioutil.ReadAll() and write all the data with into a new file with ioutil.WriteFile(), then the file is fine, but i can still not open it through my website.
Can me tell someone, how to access the tmpfile information of an multipart.file?
if r.Method == http.MethodPost {
r.ParseMultipartForm(maxUploadSize)
file, handler, err := r.FormFile("myFile")
if err != nil {
utils.InternalServerError(w)
return
}
defer file.Close()
data, err2 := ioutil.ReadAll(file)
if err2 != nil {
utils.LoggingWarningFile(err2.Error())
return
}
path = temp + "\\" + itemname + fileExt
err2 = ioutil.WriteFile(path, data, 0777)
if err2 != nil {
fmt.Println(err2)
return
}
}
I would be very happy for every tip or solution approach.
Thanks