0
When I try to upload mp3 files to S3 using the s3manager package of aws-sdk-go, I get this error.
2019/03/29 11:02:07 Error occurred while uploading
/var/recordings/98a8d64ab5d01c9e00ba4ca1e292ce61.mp3 . Error : RequestError: send request failed
caused by: Put https://<bucketName>.s3.ap-southeast-1.amazonaws.com/98a8d64ab5d01c9e00ba4ca1e292ce61.mp3: EOF Current file size: 678071
The problem is, this happens only sometimes. I have added logs to check if the files are empty or not. Everything seems fine.
Here is the code that I am using to handle the upload:
Input
fileReader := bytes.NewReader(buffer)
input := &s3manager.UploadInput{
Bucket: aws.String(awsBucketName),
Key: aws.String(filename),
ContentType: aws.String(fileType),
ACL: aws.String("public-read"),
Body: fileReader,
}
Upload function
func upload(svc s3iface.S3API, input *s3manager.UploadInput) (*s3manager.UploadOutput, error) {
if input.Body == nil {
return nil, fmt.Errorf("the body provided in input is nil")
}
uploader := s3manager.NewUploaderWithClient(svc, func(uploader *s3manager.Uploader) {
uploader.PartSize = maxPartSize
uploader.LeavePartsOnError = false
})
uploadOutput, err := uploader.Upload(input)
if err != nil {
return nil, err
}
return uploadOutput, nil
}
I don't know how to debug this. I am pretty sure this is bug in the AWS sdk. I have created an issue here. Any insight on this is helpful.