SaveFile
Method is used to save any multipart file to disk.
c.SaveFile(fh *multipart.FileHeader, path string)
app.Post("/", func(c *fiber.Ctx) {
// Parse the multipart form:
if form, err := c.MultipartForm(); err == nil {
// => *multipart.Form
// 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))
}
}
})