fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🐛 [Bug]: nil multipart.FileHeader when parsing form

Open yokeTH opened this issue 11 months ago • 2 comments

Bug Description

I try to parsing into struct that contain field type *multipart.FileHeader like this

type CreateFileRequest struct {
    File *multipart.FileHeader `form:"file"`
}
func (h *fileHandler) CreatePrivateFile(c fiber.Ctx) error {
    req := new(dto.CreateFileRequest)

    if err := c.Bind().Form(req); err != nil {
        return apperror.BadRequestError(err, "invalid file")
    }

    fileData, err := h.fileUseCase.CreatePrivateFile(c.Context(), req.File)
    if err != nil {
        return err
    }

    response, err := h.dto.ToResponse(*fileData)
    if err != nil {
        return err
    }

    return c.Status(201).JSON(dto.Success(response))
}

I got req.File is nil

How to Reproduce

Steps to reproduce the behavior:

Follow my code it simple

Expected Behavior

I should behavior like c.FormFile("file")

Fiber Version

v3.0.0-rc4

Code Snippet (optional)

// package dto
type CreateFileRequest struct {
    File *multipart.FileHeader `form:"file"`
}


// package handler
func (h *fileHandler) CreatePrivateFile(c fiber.Ctx) error {
    req := new(dto.CreateFileRequest)

    if err := c.Bind().Form(req); err != nil {
        return apperror.BadRequestError(err, "invalid file")
    }

    fileData, err := h.fileUseCase.CreatePrivateFile(c.Context(), req.File)
    if err != nil {
        return err
    }

    response, err := h.dto.ToResponse(*fileData)
    if err != nil {
        return err
    }

    return c.Status(201).JSON(dto.Success(response))
}

Checklist:

  • [x] I agree to follow Fiber's Code of Conduct.
  • [x] I have checked for existing issues that describe my problem prior to opening this one.
  • [x] I understand that improperly formatted bug reports may be closed without explanation.

yokeTH avatar May 07 '25 00:05 yokeTH

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

welcome[bot] avatar May 07 '25 00:05 welcome[bot]

Test it with go get github.com/gofiber/fiber/v3@main. It is not included to the latest release, but it is available on main branch.

efectn avatar May 16 '25 13:05 efectn

Solve It not on the currently rc version

yokeTH avatar Jun 16 '25 03:06 yokeTH