I\'m trying to get some code working to fetch a file from S3 using the REST API via C#. I\'ve seen other people doing similar things but for some reason I keep getting a 403
I tested your code, it works! you just need an extra \n plus change http to https and you're done.
string stringToConvert = "GET\n"
+ "\n"
+ "\n"
+ "\n"
+ "x-amz-date:" + timeStamp + "\n"
+ "/" + bucketName + "/" + FileName;
Amazon Rest API don't have a good documentation, the lack of examples makes everyone go to the SDK instead.
I don't know if this is the only problem, but it looks like a definite problem:
+ "x-amz-date:" + httpDate + "\n"
x-amz-date
is the header that supercedes the Date: header in the HTTP request itself, but in the string to sign, you just put the date, without "x-amz-date:" or anything in front of it, according to the examples:
GET\n
\n
\n
Tue, 27 Mar 2007 19:36:42 +0000\n
/johnsmith/photos/puppy.jpg
http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationRequestCanonicalization
There is only one correct signature that can be generated for a request. S3 is going to generate that signature, and compare it to the one you sent, so there's not a single byte of room for error in the string-to-sign.