3

When I receive a post request with a list of files to be uploaded to the server, I can get a specific file, if I know the name of it via

c.FormFile("filename")

But how would I iterate over the files in that list, without knowing the files names ahead of time? I don't see a method listed in the context docs that simply provides a list of files.

granitdev
  • 136
  • 2
  • 13

1 Answers1

7

Call c.MultiPartForm() to get a *multipart.Form. Iterate through the form's File field.

form, err := ctx.MultipartForm()
if err != nil { /* handle error */ }
for formFieldName, fileHeaders := range form.File {
    for _, fileHeader := range fileHeaders {
        // process uploaded file here
    }
}