Created
November 15, 2014 21:49
-
-
Save dpaluy/81a351d6cbf718b6d4b2 to your computer and use it in GitHub Desktop.
AWS Policy signature example
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
function sign(req, res, next) { | |
var fileName = req.body.fileName, | |
expiration = new Date(new Date().getTime() + 1000 * 60 * 5).toISOString(); | |
var policy = | |
{ "expiration": expiration, | |
"conditions": [ | |
{"bucket": bucket}, | |
{"key": fileName}, | |
{"acl": 'public-read'}, | |
["starts-with", "$Content-Type", ""], | |
["content-length-range", 2048, 20971520] | |
]}; | |
policyBase64 = new Buffer(JSON.stringify(policy), 'utf8').toString('base64'); | |
signature = crypto.createHmac('sha1', secret).update(policyBase64).digest('base64'); | |
res.json({bucket: bucket, key: awsKey, policy: policyBase64, signature: signature}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment