-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🤗 Custom response ? #747
Comments
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 |
Also make sure that your app := fiber.New(&fiber.Settings{
BodyLimit: 12 * 1024 * 1024, // 12 MB
}) func Upload() fiber.Handler {
return func(c *fiber.Ctx) {
file, err := c.FormFile("file")
if err != nil {
log.Printf("err from logger:> %s", err)
c.JSON(fiber.Map{
"message": err,
})
}
// Pass error to errorhandler
if err := c.SaveFile(file, fmt.Sprintf("./%s", file.Filename)); err != nil {
c.Next(err)
return
}
// Format JSON
c.JSON(fiber.Map{
"status": "success",
})
}
} |
Thank you so much it works now. Why do you have to |
Else it would continue to modify the response, when you return from the handler it will flush the response to the client. // v1.14.5
func Upload() fiber.Handler {
return func(c *fiber.Ctx) {
file, err := c.FormFile("file")
if err != nil {
log.Printf("err from logger:> %s", err)
c.JSON(fiber.Map{
"message": err,
})
}
if err := c.SaveFile(file, fmt.Sprintf("./%s", file.Filename)); err != nil {
c.Next(err)
return
}
c.JSON(fiber.Map{
"status": "success",
})
}
}
}
// v1.15.0 ( 15 September 2020 )
func Upload() fiber.Handler {
return func(c *fiber.Ctx) error {
file, err := c.FormFile("file")
if err != nil {
return err // calls global error handler
}
if err := c.SaveFile(file, fmt.Sprintf("./%s", file.Filename)); err != nil {
return err // calls global error handler
}
return c.JSON(fiber.Map{"status": "success"})
}
} |
Question description
im trying to return a custom response when a user completes an upload but i seems to be missing something because its not working , neither of the response seem to be working.
Code snippet Optional
The text was updated successfully, but these errors were encountered: