multipart.Reader has a field tempDir
that is private:
// Reader is an iterator over parts in a MIME multipart body.
// Reader's underlying parser consumes its input as needed. Seeking
// isn't supported.
type Reader struct {
bufReader *bufio.Reader
tempDir string // used in tests
currentPart *Part
partsRead int
nl []byte // "\r\n" or "\n" (set after seeing first boundary line)
nlDashBoundary []byte // nl + "--boundary"
dashBoundaryDash []byte // "--boundary--"
dashBoundary []byte // "--boundary"
}
When reading in large files using multipart.Reader, this field is normally an empty string and will cause the readForm method to use the system default tmp dir when reading in large files:
file, err = os.CreateTemp(r.tempDir, "multipart-")
In my case, the /tmp dir I am working is backed by tmpfs and is size restricted to the point where the files I'm uploading are too large for it. For now I'm working around the issue by setting TMPDIR environment variable, but ideally it would be wise for me to be able to control this at the request level.
My questions is if there is any reason that this variable should not be settable when the multipart.Reader struct is created. Say by adding a second argument to ctx.Request.ParseMultipartForm that takes the tmpdir as an argument and passes it to any readers it creates?
If no reason I'll whip up a patch.
Comment From: stieg
Ahh crud... This is posted in the wrong project. Should be in https://github.com/golang/go/
Comment From: stieg
Relevant discussion: https://github.com/golang/go/issues/26707