Created
September 16, 2014 22:03
-
-
Save heymichaelp/769359f58b40db4f58a7 to your computer and use it in GitHub Desktop.
s3xy-node implementation
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
app.get('/sign_s3', function(req, res){ | |
var object_name = req.query.s3_object_name; | |
var mime_type = req.query.s3_object_type; | |
var now = new Date(); | |
var expires = Math.ceil((now.getTime() + 10000)/1000); // 10 seconds from now | |
var amz_headers = "x-amz-acl:public-read"; | |
var put_request = "PUT\n\n"+mime_type+"\n"+expires+"\n"+amz_headers+"\n/"+S3_BUCKET+"/"+object_name; | |
var signature = crypto.createHmac('sha1', AWS_SECRET_KEY).update(put_request).digest('base64'); | |
signature = encodeURIComponent(signature.trim()); | |
signature = signature.replace('%2B','+'); | |
var url = 'https://'+S3_BUCKET+'.s3.amazonaws.com/'+object_name; | |
var credentials = { | |
signed_request: url+"?AWSAccessKeyId="+AWS_ACCESS_KEY+"&Expires="+expires+"&Signature="+signature, | |
url: url | |
}; | |
res.write(JSON.stringify(credentials)); | |
res.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment