SaveFile

Method is used to save any multipart file to disk.

  1. c.SaveFile(fh *multipart.FileHeader, path string)
  1. app.Post("/", func(c *fiber.Ctx) {
  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. c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
  14. }
  15. }
  16. })