Go - formFile for multiple files

2019-04-25 20:48发布

The formFile function works perfectly but in the docs it´s said that the "FormFile returns the first file for the provided form key". Is there a way of obtaining the several files that an html form with an input like:

<input type="file" name="myfiles" multiple="multiple">

might return?

标签: forms http go
1条回答
仙女界的扛把子
2楼-- · 2019-04-25 21:39

FormFile is a convenience function. You can manually parse and find the files you are looking for in the MultipartForm.

req.ParseMultipartForm(32 << 20) // 32MB is the default used by FormFile
fhs := req.MultipartForm.File["myfiles"]
for _, fh := range fhs {
    f, err := fh.Open()
    // f is one of the files
}
查看更多
登录 后发表回答