Download

Transfers the file from path as an attachment.

Typically, browsers will prompt the user to download. By default, the Content-Disposition header filename= parameter is the file path (this typically appears in the browser dialog).

Override this default with the filename parameter.

  1. c.Download(path, filename ...string) error
  1. app.Get("/", func(c *fiber.Ctx) {
  2. if err := c.Download("./files/report-12345.pdf"); err != nil {
  3. c.Next(err) // Pass err to fiber
  4. }
  5. // => Download report-12345.pdf
  6. if err := c.Download("./files/report-12345.pdf", "report.pdf"); err != nil {
  7. c.Next(err) // Pass err to fiber
  8. }
  9. // => Download report.pdf
  10. })