vishal
vishal

Reputation: 207

SignatureDoesNotMatch error when trying to access file on Amazon s3

I am trying to access the file that has been uploaded to Amazon S3 by using the method GetPreSignedUrlRequest. The code I am using is as below:-

string bucketName = string.Empty;
if (ConfigurationManager.AppSettings["S3BucketName"] != null)
{
       bucketName = ConfigurationManager.AppSettings["S3BucketName"].ToString();
}
AmazonS3Client s3Client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
{
     BucketName = bucketName,
     Key = file.FileName,
     Expires = DateTime.Now.AddMinutes(5),
     Protocol = Protocol.HTTP
};
string url = s3Client.GetPreSignedURL(request);

The url generated by this is then used to point to the file. It looks like http://s3.amazonaws.com/mybucketname/VZcbKsZgR2qyOMkLU1XT_jquery_ui_touch-punch_min_js.txt?X-Amz-Expires=300&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIMGQJ6D5L5SNBGHA/20140114/us-east-1/s3/aws4_request&X-Amz-Date=20140114T194159Z&X-Amz-SignedHeaders=host&X-Amz-Signature=922719dd2286600aebaca5701a8e142d327342b541569c9a4d7d8afc822d9a76/VZcbKsZgR2qyOMkLU1XT_jquery_ui_touch-punch_min_js.txt

But that gives me signature doesnot match error as shown in the image below:-

Signature does not match

Upvotes: 2

Views: 1847

Answers (2)

Tom
Tom

Reputation: 8180

This can also occur if some of the details about the request are not set up properly:

e.g. For me the following lines fixed the problem

        request1.ContentType = "image/jpeg";
        request1.Verb = HttpVerb.PUT;

Upvotes: 0

Steve Roberts
Steve Roberts

Reputation: 734

Update - version 2.0.6 of the SDK, released Jan 16th, contains a fix for this issue.

Your code is fine, unfortunately a bug in the SDK is causing the presigned url to be malformed. I've just tested it with our latest codebase and we've fixed the issue; this new version should be released soon.

I'll ping this issue once we release the patch. Sorry for the inconvenience.

Regards,

Upvotes: 0

Related Questions