Created
May 16, 2015 06:25
-
-
Save wei/70545a0e92e2a3058ee0 to your computer and use it in GitHub Desktop.
Manually Pre-Sign Amazon Put Request
This file contains hidden or 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 hmacSha1Base64 = function (message) { | |
return require("crypto").createHmac('sha1', process.env.AMAZON_SECRET_ACCESS_KEY) | |
.update(message) | |
.digest('base64') | |
} | |
var expires = Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 | |
var put_request = "PUT\n" + md5Base64 + "\n"+contentType+"\n"+expires+"\n/"+ "xxxxxxx/" + bucketObjectKey | |
var signature = hmacSha1Base64((process.env.AMAZON_SECRET_ACCESS_KEY, )put_request); | |
return 'https://xxxxxxx.s3.amazonaws.com/'+ bucketObjectKey + | |
'?AWSAccessKeyId=' + encodeURIComponent(process.env.AWS_ACCESS_KEY_ID) + | |
'&Content-MD5=' + md5Base64 + | |
"&Content-Type=" + encodeURIComponent(contentType) + | |
"&Expires=" + encodeURIComponent(expires) + | |
"&Signature=" + encodeURIComponent(signature) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment