Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created November 15, 2014 21:49
Show Gist options
  • Save dpaluy/81a351d6cbf718b6d4b2 to your computer and use it in GitHub Desktop.
Save dpaluy/81a351d6cbf718b6d4b2 to your computer and use it in GitHub Desktop.
AWS Policy signature example
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