-
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 retrieve multiple files continuously #719
Comments
I have found a way that works by turning the multipart form into a reader. Here is a code snippet without full error handling:
|
@HuanjunKong sorry for late reply, @Michael77 is another solution but I see that you could not access directly a file by name. |
I had to do something similar--transferring multiple file uploads to S3 in parallel. Adding to @Michael77 method if you need access to the original filename you can use the mime package. disposition, params, err := mime.ParseMediaType(part.Header.Get("Content-Disposition"))
if err != nil {
break
}
filename := params["filename"] |
hey @jeffkoncz any chance you have a larger example of this? I'm a bit stuck, doing the exact same thing. |
@genexp You can see the example https://github.com/gin-gonic/gin/blob/develop/examples/upload-file/multiple/main.go |
@genexp Here's some code that is specific to transferring multiple file uploads to S3. Hopefully it can get you unstuck :) : func MultipartUploadHandler(c *gin.Context) {
multipart, err := c.Request.MultipartReader()
if err != nil {
log.Fatalln("Failed to create MultipartReader", err)
}
for {
mimePart, err := multipart.NextPart()
if err == io.EOF {
break
}
if err != nil {
log.Printf("Error reading multipart section: %v", err)
break
}
disposition, params, err := mime.ParseMediaType(mimePart.Header.Get("Content-Disposition"))
if err != nil {
log.Printf("Invalid Content-Disposition: %v", err)
break
}
// S3 Upload Manager
uploader := s3manager.NewUploader(session.New(&aws.Config{Region: aws.String("us-west-2")}))
result, err := uploader.Upload(&s3manager.UploadInput{
Body: mimePart,
Bucket: aws.String("yourbucket"),
Key: aws.String(params["filename"]),
ContentType: aws.String(mimePart.Header.Get("Content-Type")),
ACL: aws.String("public-read"),
})
if err != nil {
log.Fatalln("Failed to upload to S3", err)
}
c.JSON(http.StatusOK, gin.H{
"location": result.Location,
})
}
} |
@jeffkoncz Yeah, this is awesome. Thanks so much! |
Awesome! Thanks! |
After checking #562 , I post 10 images (500KB) to
gin
, code :c.Request.FormFile
cost a lot time. It seems like thatFormFile
returnsfile
after retrieved all 10 files.Face recognition is time-consuming algorithm, this workflow should be better:
just like a link list.
My question is how to retrieve files like traverse linked list.
The text was updated successfully, but these errors were encountered: