12

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?

4

1 回答 1

20

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
}
于 2013-03-04T14:55:19.330 回答