I've successfully uploaded a file to Amazon S3 using a signed url request generated by Amazons Java library:
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucket, objectName)
generatePresignedUrlRequest.
withContentType(contentType).
withMethod(HTTPMethod.PUT)
URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest)
I changed HTTPMethod.PUT
to HTTPMethod.GET
and called it with the same arguments.
When I paste the resulting URL into my browser, I get:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
<AWSAccessKeyId>XXXX</AWSAccessKeyId>
<StringToSign>GET 1449712291 /my-bucket/picture.png</StringToSign>
....
</Error>
Is there a way to pull the so-called StringToSign
being used out of the presigned request object to compare? Or is there another way to troubleshoot this?
答案 0 :(得分:2)
withContentType(contentType)
这条线没有意义。您不会为Content-Type:
请求设置GET
,因为该标题会描述您发送的内容 - 这是&#34;没有&#34} ;对于典型的GET
请求。由于这是要签名的字符串的组件之一,并且错误响应显示S3希望它为空,因此删除它应该可以解决问题。