Skip to content

How to Handle Multiple File Uploads in GoFr? #2446

@Thomas-Matheus

Description

@Thomas-Matheus

Hi GoFr team! 👋

I'm using GoFr (v1.46.0) and currently have single file upload working perfectly. However, I'd like to extend this functionality to support multiple file uploads in a single request, and I'm not sure about the best approach with GoFr's context binding system.

Current Implementation (Single File Upload)

DTO Structure:

type FileUploadDTO struct {
    File *multipart.FileHeader `file:"file"`
}

Handler:

func (h *FileHandler) UploadFile(ctx *gofr.Context) (any, error) {
    var upload dto.FileUploadDTO
    if err := ctx.Bind(&upload); err != nil {
        return nil, err
    }
...
}

This works great for single files, but I need to support multiple files in one request.

What I'm Looking For

  1. Does GoFr's ctx.Bind() support binding multiple files automatically? For example, would something like this work:

    type MultiFileUploadDTO struct {
        Files []*multipart.FileHeader `file:"files"`
    }

Actually I tried this approach but didn't work properly

  1. Is there a recommended GoFr pattern for handling bulk file uploads with proper error handling and validation?

Use Case

Users need to upload multiple trip photos/documents simultaneously (e.g., 5-10 files at once) rather than making individual requests for each file.

Environment

  • GoFr Version: 1.46.0
  • Go Version: 1.25

Any guidance or examples would be greatly appreciated! Thanks for the awesome framework! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriageThe issue needs triaging.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions