Multiple files

See the detail example code.

  1. func main() {
  2. router := gin.Default()
  3. // Set a lower memory limit for multipart forms (default is 32 MiB)
  4. router.MaxMultipartMemory = 8 << 20 // 8 MiB
  5. router.POST("/upload", func(c *gin.Context) {
  6. // Multipart form
  7. form, _ := c.MultipartForm()
  8. files := form.File["upload[]"]
  9. for _, file := range files {
  10. log.Println(file.Filename)
  11. // Upload the file to specific dst.
  12. c.SaveUploadedFile(file, dst)
  13. }
  14. c.String(http.StatusOK, fmt.Sprintf("%d files uploaded!", len(files)))
  15. })
  16. router.Run(":8080")
  17. }

How to curl:

  1. curl -X POST http://localhost:8080/upload \
  2. -F "upload[]=@/Users/appleboy/test1.zip" \
  3. -F "upload[]=@/Users/appleboy/test2.zip" \
  4. -H "Content-Type: multipart/form-data"

Last modified May 27, 2020 : chore: uncomment the code (#123) (7e8c3a0)