Advertisement
Pater92

s3 uploader issue connection hopping

Dec 5th, 2019
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.84 KB | None | 0 0
  1. const (
  2.     awsBucketRegion = "YOUR-BUCKET-REGION"
  3.     awsBucketName   = "YOUR-BUCKET-NAME"
  4.     partSize        = 5 * 1024 * 1024
  5.     maxRetry        = 1
  6. )
  7.  
  8. // AddFileS3 add a new file to the multipart.
  9. func AddFileS3Compressed(fileName string, reader io.ReadCloser) (*s3manager.UploadOutput, error) {
  10.     // Create a single AWS session (we can re use this if we're uploading many files)
  11.     cfg := &aws.Config{
  12.         Region:     aws.String(awsBucketRegion),
  13.         MaxRetries: aws.Int(maxRetry),
  14.     }
  15.     // with logger need to be added.
  16.     svc := session.Must(session.NewSession(cfg))
  17.     uploader := s3manager.NewUploader(svc)
  18.     uploader.PartSize = partSize
  19.  
  20.     result, err := uploader.Upload(&s3manager.UploadInput{
  21.         Body:   reader,
  22.         Bucket: aws.String(awsBucketName),
  23.         Key:    aws.String(fileName),
  24.     })
  25.     if err != nil {
  26.         return nil, err
  27.     }
  28.     return result, nil
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement