-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to upload array of files with params #774
Labels
Comments
@andreynering does this also work with your form array value patch? |
Haven't tried by I don't think so.
|
@tboerger @selvam347 @andreynering I create new PR to support upload single or multiple files. #775 upload single file:package main
import (
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func main() {
router := gin.Default()
router.POST("/upload", func(c *gin.Context) {
// single file
file, _ := c.FormFile("file")
log.Println(file.Filename)
c.String(http.StatusOK, "Uploaded...")
})
router.Run(":8080")
} curl command: curl -X POST http://localhost:8080/upload -F "file=@/Users/mtk10671/z.sh" -H "Content-Type: multipart/form-data" upload multiple file:package main
import (
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func main() {
router := gin.Default()
router.POST("/upload", func(c *gin.Context) {
// Multipart form
form, _ := c.MultipartForm()
files := form.File["upload[]"]
for _, file := range files {
log.Println(file.Filename)
}
c.String(http.StatusOK, "Uploaded...")
})
router.Run(":8080")
} curl command: curl -X POST http://localhost:8080/upload -F "upload[]=@/Users/mtk10671/z.sh" -F "upload[]=@/Users/mtk10671/z.sh" -H "Content-Type: multipart/form-data" |
Closed by #775 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can upload single file using https://github.com/gin-gonic/gin/issues/548.
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,
The text was updated successfully, but these errors were encountered: