Skip to content

Ability to presign #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/S3Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ const DEFAULT_SUCCESS_ACTION_STATUS = "201";
export class S3Policy {
static generate(options) {
options || (options = {});

// always required
assert(options.accessKey, "Must provide `accessKey` option with your AWSAccessKeyId");
assert(options.key, "Must provide `key` option with the object key");
assert(options.bucket, "Must provide `bucket` option with your AWS bucket name");
assert(options.contentType, "Must provide `contentType` option with the object content type");
assert(options.region, "Must provide `region` option with your AWS region");
assert(options.accessKey, "Must provide `accessKey` option with your AWSAccessKeyId");

if (options.presign) {
assert(options.acl, "Must provide 'acl' with presign option");
assert(options.policy, "Must provide 'policy' with presign option");
assert(options.signature, "Must provide 'signature' with presign option");
return formatPolicyForPresign(options);
}

assert(options.secretKey, "Must provide `secretKey` option with your AWSSecretKey");
assert(options.bucket, "Must provide `bucket` option with your AWS bucket name");
assert(options.region, "Must provide `region` option with your AWS region");

let policyParams = getPolicyParams(options);
let policy = formatPolicyForEncoding(policyParams);
Expand Down Expand Up @@ -105,6 +115,17 @@ const formatPolicyForEncoding = (policy) => {
}
}

const formatPolicyForPresign = (options) => {
return {
"key": options.key,
"AWSAccessKeyId": options.accessKey,
"acl": options.acl,
"policy": options.policy,
"signature": options.signature,
"Content-Type": options.contentType,
}
}

const getEncodedPolicy = (policy) => {
return new Buffer(
JSON.stringify(policy),
Expand Down