Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go - formFile for multiple files

Tags:

http

forms

go

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?

like image 268
AlvaroSantisteban Avatar asked Mar 04 '13 13:03

AlvaroSantisteban


1 Answers

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
}
like image 109
Stephen Weinberg Avatar answered Sep 28 '22 08:09

Stephen Weinberg