Skip to content

Instantly share code, notes, and snippets.

@elliotforbes
Created February 22, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotforbes/42edddaf08107d28e6c72148d1e0dc0b to your computer and use it in GitHub Desktop.
Save elliotforbes/42edddaf08107d28e6c72148d1e0dc0b to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
module.exports.requestUploadURL = (event, context, callback) => {
var s3 = new AWS.S3();
var params = JSON.parse(event.body);
var s3Params = {
Bucket: 'imgur-serverless',
Key: params.name,
ContentType: params.type,
Expires: 3600,
ACL: 'public-read'
};
var uploadURL = s3.getSignedUrl('putObject', s3Params);
callback(null, {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({ uploadURL: uploadURL }),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment