Last active
August 29, 2015 14:24
-
-
Save eventhough/ffdd74568fd0e1e7a4e5 to your computer and use it in GitHub Desktop.
Method to generate signed URL for AWS S3
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
var aws = require('aws-sdk'); | |
aws.config.update({ | |
accessKeyId: AWS_ACCESS_KEY | |
secretAccessKey: AWS_SECRET_KEY | |
}); | |
exports = module.exports = { | |
sign: function(filename, filetype) { | |
var s3 = new aws.S3(); | |
var params = { | |
Bucket: SOME_BUCKET, | |
Key: filename, | |
Expires: 60, | |
ContentType: filetype | |
}; | |
s3.getSignedUrl(‘putObject’, params, function(err, data) { | |
if (err) { | |
console.log(err); | |
return err; | |
} else { | |
return data; | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment