LearnBoost/knox — Issue #56: SignatureDoesNotMatch Issue
Author: alhui
Created: 2011-12-29 06:46:10+00:00
State: open

I've worked through numerous examples on this, but still receiving a SignatureDoesNotMatch error when I try to 'put()' a jpeg into S3.

I've used the amazon s3 signature testing tool to troubleshoot and identified a difference between the request I am sending and what amazon expects.

What the amazon test tool expects when I enter the hexcode returned in the StringToSign section,

PUT\n\nimage/jpeg\nThu, 29 Dec 2011 06:32:18 GMT\nx-amz-acl:public-read\n/girlsafaritest2\28.jpg

What I am seeing in console.log in the request object I send out to amazon via the put() call in Knox,

_header: 'PUT \\28.jpg HTTP/1.1\r\nExpect: 100-continue\r\nx-amz-acl: public-r
ead\r\nContent-Length: 45800\r\nContent-Type: image/jpeg\r\nDate: Thu, 29 Dec 20
11 06:32:18 GMT\r\nHost: girlsafaritest2.s3.amazonaws.com\r\nAuthorization: AWS
AKIAJ3S7Y6CDASJHLUWA:Tm+8/ljOevwZnoV9sEzduo4rYhw=\r\nConnection: keep-alive\r\n\
r\n'

Almost everything matches except I noticed that there are two differences, 1) - the \\28.jpg (is the \\ causing a problem?) and 2) Amazon expects \n while in the request it uses \r\n (is windows causing an issue? I am running nodejs/knox from Win7)

In case anyone wants to see the code I am using, here it is as well:

fs.readFile('./public/images/mockdata/28.jpg', function(err, buf){
console.log('readfile completed, length is: ' + buf.length);
var req = client.put('28.jpg', {
'Content-Length': buf.length
, 'Content-Type': 'image/jpeg'
});

console.log(req);

req.on('response', function(res){
console.log('[Response]:\n\r res.statusCode: ' + res.statusCode);
console.log('res.headers: ' + res.headers);
res.on('data', function(chunk){
console.log('chunk string: ' + chunk.toString());
});
if (200 == res.statusCode) {
console.log('saved to %s', req.url);
}
});
req.end(buf);
});

Appreciate any help anyone can provide!