-
-
Save bhanuc/bda0c4b48aa39fdf8aa2 to your computer and use it in GitHub Desktop.
S3 Server singing Code
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
router.get('/sign_s3', function * () { | |
var object_name = this.request.query.s3_object_name; | |
var mime_type = this.request.query.s3_object_type; | |
var now = new Date(); | |
var expires = Math.ceil((now.getTime() + 1000000) / 1000); // 1000 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 = signature.replace('+','%2B').replace('/','%2F').replace('=','%3D'); | |
signature = encodeURIComponent(signature.trim()); | |
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 | |
}; | |
this.body = JSON.stringify(credentials); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment