Skip to content

Instantly share code, notes, and snippets.

@moudy
Created October 16, 2015 16:25
Show Gist options
  • Save moudy/445682a38e89c0b1474b to your computer and use it in GitHub Desktop.
Save moudy/445682a38e89c0b1474b to your computer and use it in GitHub Desktop.
var policy = require('s3-policy');
var Route = require('project-router').Route;
var S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
var S3_KEY = process.env.S3_KEY;
var S3_SECRET = process.env.S3_SECRET;
var PUBLIC_READ_ACL = 'public-read';
module.exports = Route.extend({
model: function () {
return policy({
secret: S3_SECRET,
bucket: S3_BUCKET_NAME,
key: S3_KEY,
expires: new Date(Date.now() + 60000),
acl: PUBLIC_READ_ACL,
conditions: [{success_action_status: '200'}]
});
},
responseData: function (model) {
var policy = {
AWSAccessKeyId: S3_KEY,
acl: PUBLIC_READ_ACL,
policy: model.policy,
signature: model.signature,
success_action_status: 200,
'Content-Length': ''
};
return {
policy: policy,
s3BucketName: S3_BUCKET_NAME
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment