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