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.
c.MultipartForm() (*multipart.Form, error)
app.Post("/", func(c *fiber.Ctx) {
// Parse the multipart form:
if form, err := c.MultipartForm(); err == nil {
// => *multipart.Form
if token := form.Value["token"]; len(token) > 0 {
// Get key value:
fmt.Println(token[0])
}
// Get all files from "documents" key:
files := form.File["documents"]
// => []*multipart.FileHeader
// Loop through files:
for _, file := range files {
fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
// => "tutorial.pdf" 360641 "application/pdf"
// Save the files to disk:
c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
}
}
})