Description
Hi, I'm coding a function which receives a large file like this:
// receive file
formFile, err := c.FormFile("myfile") // stuck if file is large
// open this file
f, err := formFile.Open()
// upload this file to other storage service
err = uploadFileToStorageService(f)
Everything is OK if this file is not large. But my function will stuck in FormFile() if file is large. As far as I know, FormFile() may write a temp file to disk, that's why it takes such a long time until it returns if file is large.
So, is there a way to just transfer form file data in memory ?
Environment
- go version: 1.17.3
- gin version (or commit ref): v1.7.4
- operating system: CentOS 8.1
Comment From: Fov6363
if filesize > engine.MaxMultipartMemory(defaultMultipartMemory(32MB)) // it's write file to disk.
so you can change MaxMultipartMemory(int64) to aviod write disk
write disk is package http
behavior, gin only control size.
Comment From: AmazingPangWei
Thanks for your reply. But my file may be very large, changing MaxMultipartMemory, in my opinion, is not a good idea.
I'll look up package http
and try to work out this issue.