s3-post-policy
A POST policy generator for S3 using AWS Signature Version 4
Example
var policy_gen = require("s3-post-policy");
var policy = policy_gen({
id: "AKIAIOSFODNN7EXAMPLE",
secret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
date: Date.now(),
region: "us-east-1",
bucket: "examplebucket",
policy: {
expiration: Date.now() + 60 * 1000,
conditions: [
{"acl": "public-read"},
["starts-with", "$Content-Type", "image/"],
["starts-with", "$key", "user/user1/"],
["starts-with", "$x-amz-meta-tag", ""],
{"x-amz-meta-uuid": "14365123651274"}
]
}
});
console.log(policy);
API
s3-post-policy exports a single function that returns a Object
function policy_gen({
id: "AKIAIOSFODNN7EXAMPLE", // Your AWS key id
secret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", // Your AWS secret key
date: Date.now(), // The date of the request in any format that "new Date()" can parse
region: "us-east-1", // The region that is receiving the request
bucket: "examplebucket", // The bucket that is receiving the request
policy: {
expiration: Date.now() + 60 * 1000, // When the request should expire in any format that "new Date()" can parse
conditions: [
// An array of valid policy conditions
// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
]
}
})