You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type MyForm struct {
File *multipart.FileHeader `form:"file" validate:"required"`
}
app.Post("/upload-v1", func(c *fiber.Ctx) error {
// Parse the request body into MyForm
form := new(MyForm)
if err := c.BodyParser(form); err != nil {
msg := fmt.Sprintf("Failed to parse the request body: %s", err.Error())
return c.Status(http.StatusBadRequest).JSON(&fiber.Map{"ok": false, "msg": msg})
}
log.Printf("form: %+v", form) // <= this return form.File null
return c.Status(http.StatusOK).JSON(&fiber.Map{"ok": true})
})
i call the upload with this curl:
curl -X POST -F "file=@/tmp/data/test-data.txt" \
http://localhost:3000/upload-v1
it give me form: &{File:<nil>} on the console.
and return error Validation failed: Key: 'MyForm.File' Error:Field validation for 'File' failed on the 'required' tag
what is the proper way to work wtih form data validation and body parser? does it support form data validation?
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
Question Description
i call the upload with this curl:
it give me
form: &{File:<nil>}
on the console.and return error
Validation failed: Key: 'MyForm.File' Error:Field validation for 'File' failed on the 'required' tag
what is the proper way to work wtih form data validation and body parser? does it support form data validation?
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: