MultipartForm

To access multipart form entries, you can parse the binary with MultipartForm(). This returns a map[string][]string, so given a key the value will be a string slice.

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