I have a node.js app that periodically pushes some data to Amazon S3. I'm using a Put request to push a buffer over to S3.
I know that the "content-md5" parameter of the S3 request needs to be the base64 encoded Md5 hash of the content that I'm pushing. What has me confused is that 90% of the time, my requests succeed. The other 10% of the time, without my hashing method changing at all, Amazon gives me back "badDigest" error:
{ [Error: API error with HTTP Code: 400]
headers:
{
'content-type': 'application/xml',
'transfer-encoding': 'chunked',
date: 'Fri, 06 Apr 2012 02:20:14 GMT',
connection: 'close',
server: 'AmazonS3' },
code: 400,
document:
{ Code: 'BadDigest',
Message: 'The Content-MD5 you specified did not match what we received.',
ExpectedDigest: 'fPRrmxapcSHmI2gljme1Fg==',
CalculatedDigest: 'w6PoDxh2ty478+Mw2UwTrA==',
RequestId: '1018E7A80A8B0B00',
HostId: 'W/SK/OovQHlsi593DJ154pkHdOrUk3oMWmIGNdOKj3WaHa8cBknhB+7H5IdZLUjt' } }
Has anyone else experienced this randomness from S3 before? Am I missing something obvious?
Thanks!
You likely forgot to specify 'utf8'
as parameter for update
.
var status = 'काक्नोम्यत्क्नोम्यत्चं शक्नोम्यत्तुमतुम् ।तुम् ।् । नोपहिनस्ति माम् ॥';
var contentMd5 = crypto
.createHash('md5')
.update(status, 'utf8')
.digest('base64');
Without it works in the most cases but not when your string includes multibyte characters.