-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
43 lines (39 loc) · 1009 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package s3lib
import (
"bytes"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
)
// Uploads the fileBytes bytearray a MultiPart upload
func (s *S3Session) multipartUpload(resp *s3.CreateMultipartUploadOutput, fileBytes []byte, partNum int) (completedPart *s3.CompletedPart, err error) {
var try int
for try <= _RETRIES {
uploadResp, err := s.UploadPart(&s3.UploadPartInput{
Body: bytes.NewReader(fileBytes),
Bucket: resp.Bucket,
Key: resp.Key,
PartNumber: aws.Int64(int64(partNum)),
UploadId: resp.UploadId,
ContentLength: aws.Int64(int64(len(fileBytes))),
})
// Upload failed
if err != nil {
fmt.Println(err)
// Max retries reached! Quitting
if try == _RETRIES {
return nil, err
} else {
// Retrying
try++
}
} else {
// Upload is done!
return &s3.CompletedPart{
ETag: uploadResp.ETag,
PartNumber: aws.Int64(int64(partNum)),
}, nil
}
}
return nil, nil
}