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.  
  6. // Get all files from "documents" key:
  7. files := form.File["documents"]
  8. // => []*multipart.FileHeader
  9.  
  10. // Loop through files:
  11. for _, file := range files {
  12. fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
  13. // => "tutorial.pdf" 360641 "application/pdf"
  14.  
  15. // Save the files to disk:
  16. c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
  17. }
  18. }
  19. })