Hi All,
I’m using the below file upload handler code at the server side, to upload files…
func fileUpload(req *http.Request) {
req.ParseMultipartForm(32<< 20)
file, handler, err := req.FormFile("datafile")
if err != nil {
fmt.Println("Error Retrieving the File")
fmt.Println(err)
return
}
defer file.Close()
fmt.Printf("Uploaded File: %+v\n", handler.Filename)
fmt.Printf("File Size: %+v\n", handler.Size)
fmt.Printf("MIME Header: %+v\n", handler.Header)
f, err := os.OpenFile("./"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
}
When I upload files of size ~500 MB in size – the above code uses up ~500 MB RAM size.
I’m running the http server on a device and I need to limit the RAM memory my Go Application can make use of.
I think, req.FormFile("") is using up RAM memory linear to size of uploaded file. Can the buffer size be limited, so that irrespective of uploaded file size - RAM utilization is under a specified limit.
If that means, it would take little longer time for file transfer -that fine.
Can the file upload be done any differently?
I’m stuck with this for a while now - any help is greatly appreciated.
Thanks,