SaveFile

Method is used to save any multipart file to disk.

  1. func (c *Ctx) SaveFile(fh *multipart.FileHeader, path string) error
  1. app.Post("/", func(c *fiber.Ctx) error {
  2. // Parse the multipart form:
  3. if form, err := c.MultipartForm(); err == nil {
  4. // => *multipart.Form
  5. // Get all files from "documents" key:
  6. files := form.File["documents"]
  7. // => []*multipart.FileHeader
  8. // Loop through files:
  9. for _, file := range files {
  10. fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
  11. // => "tutorial.pdf" 360641 "application/pdf"
  12. // Save the files to disk:
  13. if err := c.SaveFile(file, fmt.Sprintf("./%s", file.Filename)); err != nil {
  14. return err
  15. }
  16. }
  17. return err
  18. }
  19. })