Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3.PutObject() 'x-amz-content-sha256' header does not match #148

Closed
ando-masaki opened this issue Mar 27, 2015 · 5 comments
Closed

s3.PutObject() 'x-amz-content-sha256' header does not match #148

ando-masaki opened this issue Mar 27, 2015 · 5 comments

Comments

@ando-masaki
Copy link

s3.PutObject() always returns error "The provided 'x-amz-content-sha256' header does not match what was computed.".

How can I fix it?

@iNickGo
Copy link
Contributor

iNickGo commented Mar 27, 2015

do you have sample code that will get this error?

@lsegal lsegal added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 27, 2015
@ando-masaki
Copy link
Author

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)
        }

@lsegal
Copy link
Contributor

lsegal commented Mar 30, 2015

The sample provided is the correct way to send this request.

@ando-masaki
Copy link
Author

And I used ContentLength, I caught following error.

A header you provided implies functionality that is not implemented

Therefore, I don't use ContentLength.

@lsegal
Copy link
Contributor

lsegal commented Mar 30, 2015

@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!

@lsegal lsegal closed this as completed Mar 30, 2015
@diehlaws diehlaws removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 30, 2019
ghost pushed a commit to terwanerik/S3 that referenced this issue Apr 18, 2019
…ovided 'x-amz-content-sha256' header does not match what was computed.' error (checkout aws/aws-sdk-go#148 (comment) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants