-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
s3.PutObject() 'x-amz-content-sha256' header does not match #148
Comments
do you have sample code that will get this error? |
Following way, I caught error "The provided 'x-amz-content-sha256' header does not match what was computed.". bucket := "foo"
key := "bar"
req := s3.PutObjectInput{
ACL: aws.String("private"),
Body: aws.ReadSeekCloser(buf),
Bucket: aws.String(bucket),
ContentEncoding: aws.String("gzip"),
ContentLength: aws.Long(int64(buf.Len())),
ContentMD5: func() *string {
h := md5.New()
h.Write(buf.Bytes())
return aws.String(base64.StdEncoding.EncodeToString(h.Sum(nil)))
}(),
ContentType: aws.String("application/x-gzip"),
Key: key,
}
if _, err = cfg.S3.PutObject(&req); err != nil {
log.Fatal(err)
} I solved it to change Body parameter and not use ContentLength. bucket := "foo"
key := "bar"
req := s3.PutObjectInput{
ACL: aws.String("private"),
Body: bytes.NewReader(buf.Bytes()),
Bucket: aws.String(bucket),
ContentEncoding: aws.String("gzip"),
ContentMD5: func() *string {
h := md5.New()
h.Write(buf.Bytes())
return aws.String(base64.StdEncoding.EncodeToString(h.Sum(nil)))
}(),
ContentType: aws.String("application/x-gzip"),
Key: key,
}
if _, err = cfg.S3.PutObject(&req); err != nil {
log.Fatal(err)
} |
The sample provided is the correct way to send this request. |
And I used ContentLength, I caught following error.
Therefore, I don't use ContentLength. |
@ando-masaki generally you don't need to provide a ContentLength manually as the SDK will generate this for you. This is only needed if you want to override the default behavior or if the SDK cannot determine the length itself. I am going to mark this as closed since you got it working, but we will be making improvements to the PutObject parameters in the near future. Thanks for reporting! |
…ovided 'x-amz-content-sha256' header does not match what was computed.' error (checkout aws/aws-sdk-go#148 (comment) )
s3.PutObject() always returns error "The provided 'x-amz-content-sha256' header does not match what was computed.".
How can I fix it?
The text was updated successfully, but these errors were encountered: