-
I want to upload the bigger files (videos) to AWS S3 bucket directly from echo file handler than saving the file to local drive and upload to S3 bucket as a multi part request. In the below code, I copied the file content to bytes.Buffer, but I am not sure its correct or not. Kindly help me!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Combine also you could modify this Gin example for Echo https://medium.com/wesionary-team/aws-sdk-for-go-and-uploading-a-file-using-s3-bucket-df7425317a40 or use SDK example https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#example_NewUploader_overrideReadSeekerProvider file, err := c.FormFile("file")
if err != nil {
return err
}
src, err := file.Open()
if err != nil {
return err
}
defer src.Close()
sess := session.Must(session.NewSession())
uploader := s3manager.NewUploader(sess, func(u *s3manager.Uploader) {
// Define a strategy that will buffer 25 MiB in memory
u.BufferProvider = s3manager.NewBufferedReadSeekerWriteToPool(25 * 1024 * 1024)
})
_, err := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String("examplebucket"),
Key: aws.String("largeobject"),
Body: src,
}) |
Beta Was this translation helpful? Give feedback.
Combine
start of this https://echo.labstack.com/cookbook/file-upload/
with that https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/go/example_code/s3/s3_upload_object.go
also you could modify this Gin example for Echo https://medium.com/wesionary-team/aws-sdk-for-go-and-uploading-a-file-using-s3-bucket-df7425317a40
or use SDK example https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#example_NewUploader_overrideReadSeekerProvider