Created
July 30, 2015 18:22
-
-
Save rhossi/d32c7a0ebd15f8fec0e1 to your computer and use it in GitHub Desktop.
Uploading files to S3 validating ContentMD5 using AWS SDK for Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var aws = require('aws-sdk'), | |
fs = require('fs'), | |
crypt = require("crypto"); | |
function getMD5HashFromFile(file){ | |
var hash = crypt.createHash("md5") | |
.update(file) | |
.digest("base64"); | |
return hash; | |
} | |
fs.readFile('demo-diebold.txt', function (err, data) { | |
if (err) { throw err; } | |
var fileData = new Buffer(data, 'binary'); | |
var md5Hash = getMD5HashFromFile(data); | |
var s3 = new aws.S3(); | |
s3.putObject({ | |
Bucket: 'megasenateste', | |
Key: 'diebold-demo.txt', | |
Body: fileData, | |
ContentMD5: md5Hash | |
},function (resp) { | |
console.log(arguments); | |
}); | |
}); |
how can I use this S3 validating ContentMD5 using AWS SDK in pure javascript?
Hi, how can I get the Hash from an uploaded file via ApiGateway (Base64). Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for making my Friday morning just a little easier :)
new Buffer()
is deprecated nowadays in favour ofBuffer.from()
.