-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Issue Description
Maybe in a future version of Echo, the return variables of Context#FormFile could be changed to return also the file descriptor, to avoid the cost of open it from multipart.FileHeader, which is already performed in Go net/http/request stdlib. The only advantage that I can see in the current signature of Context#FormFile is that the user is not responsible for closing the file descriptor, which reduces the cost of a File Descriptor leak vs opening the same file twice.
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
The file descriptor obtained from net/http/request is return open, to avoid to reopen it later on in the caller function
Actual behaviour
The file descriptor obtained from net/http/request is Close()
Line 368 in ad3be08
f.Close() |
And that file needs to be open again by the caller of Context#FormFile
Related code
Lines 363 to 370 in ad3be08
func (c *context) FormFile(name string) (*multipart.FileHeader, error) { | |
f, fh, err := c.request.FormFile(name) | |
if err != nil { | |
return nil, err | |
} | |
f.Close() | |
return fh, nil | |
} |