Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Fiber's context, how do I iterate over multiple files?

Tags:

go

go-fiber

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.

like image 652
granitdev Avatar asked Sep 16 '25 17:09

granitdev


1 Answers

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
    }
}
like image 61
2 revsuser19310297 Avatar answered Sep 19 '25 06:09

2 revsuser19310297