Created
June 3, 2013 15:01
-
-
Save johnnyhalife/5698816 to your computer and use it in GitHub Desktop.
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 util = require('util'), | |
crypto = require('crypto'); | |
function getSharedSignature(bucket, path) { | |
var now = new Date().getTime(); | |
var expires = Math.round((now + 10 * 365 * 24 * 3600 * 1000) / 1000); // Ten years | |
var cannonicalPath = util.format("/%s/%s", bucket, path); | |
var stringToSign = util.format("GET\n\n\n%s\n%s", expires, cannonicalPath); | |
var signature = crypto.createHmac("sha1", process.env.AWS_ACCESS_SECRET).update(stringToSign).digest("base64"); | |
var data = { expiration: expires, signature: signature, key: process.env.AWS_ACCESS_KEY }; | |
return data; | |
}; | |
// Aca se pone el path del archivo (1 o más) | |
var files = ['jbmdarling/1370188055324.docx', 'jbmdarling/1370260785584.pdf', 'jbmdarling/1370260747955.pdf', 'jbmdarling/1370200977600.pdf']; | |
for (var i in files) { | |
var filePath = files[i]; | |
var root = 'https://s3.amazonaws.com/upload.mural.ly'; | |
var path = [ root, filePath ].join('/'); | |
var cred = getSharedSignature('upload.mural.ly', filePath); | |
var query = "?AWSAccessKeyId=" + cred.key + "&Signature=" + encodeURIComponent(cred.signature) + "&Expires=" + cred.expiration; | |
var link = path + query; | |
console.log(link); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment