Closed
Description
I can upload single file using https://github.com/gin-gonic/gin/issues/548.
package main
import "github.com/gin-gonic/gin"
import "log"
import "net/http"
import "io"
import "os"
func main() {
router := gin.Default()
router.POST("/upload", func(c *gin.Context) {
file, handler, err := c.Request.FormFile("upload")
filename := handler.Filename
log.Println("Received file:", handler.Filename)
out, err := os.Create("./tmp/" + filename)
if err != nil {
log.Fatal(err)
}
defer out.Close()
_, err = io.Copy(out, file)
if err != nil {
log.Fatal(err)
}
c.String(http.StatusOK, "Uploaded...")
})
router.Run(":8080")
}
But how to upload array of files like the following,
curl -X POST http://localhost:8080/upload -F "images[]=@/home/amp/hack/property1.jpg" -F "images[]=@/home/ack/property2.jpeg" -H "Content-Type: multipart/form-data"
And give me suggestion for the same above code, how to get some parameters with documents. Finally request will be like,
{
"client": {
"name": "",
"Industry": "",
"profile_image": "PROFILE-IMAGE-FILE",
"supporting_docs": {
"docs": [
"DOCUMENT1-FILE",
"DOCUMENT2-FILE"
],
"comments": "Comment test"
}
}
}