in iot-onboarding-service/src/cloudrack-lambda-core/s3/s3.go [211:241]
func (s3c S3Config) UploadFile(key string, filePath string) error {
sess, _ := session.NewSession(&aws.Config{
Region: aws.String(s3c.Region)},
)
// Create an uploader with the session and custom options
uploader := s3manager.NewUploader(sess, func(u *s3manager.Uploader) {
u.PartSize = 5 * 1024 * 1024 // The minimum/default allowed part size is 5MB
u.Concurrency = 2 // default is 5
})
//open the file
f, err := os.Open(filePath)
if err != nil {
log.Printf("failed to open file %q, %v", filePath, err)
return err
}
// Upload the file to S3.
_, err2 := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(s3c.Bucket),
Key: aws.String(key),
Body: f,
})
if err2 != nil {
log.Printf("File upload faile with error %+v", err)
return err2
}
return nil
}