I'm currently trying to implement a system that verifies the integrity of files I upload to S3. Through the AWS SDK for JavaScript, I am able to retrieve the ETag of the remote object, however, the MD5 hash for my local object doesn't match the ETag. I am currently using crypto for generating it, as follows:
var hash = crypto.createHash('md5');
stream = fs.createReadStream(localfile);
stream.on('data', function (data) {
hash.update(data, 'utf8')
})
stream.on('end', function () {
md5 = hash.digest('hex');
< rest of the code >
});
According to all the results I've found while looking for answers, the ETags for S3 objects should be simple MD5 hashes: e.g. the AWS documentation (emphasis mine):
To ensure that data is not corrupted traversing the network, use the Content-MD5 header. When you use this header, Amazon S3 checks the object against the provided MD5 value and, if they do not match, returns an error. Additionally, you can calculate the MD5 while putting an object to Amazon S3 and compare the returned ETag to the calculated MD5 value.
However, my local hash doesn't match the remote ETag. Am I missing anything here?
Thanks for your time!
via finferflu
No comments:
Post a Comment