Last active
May 25, 2016 11:59
-
-
Save manjeshpv/ee50a5a6c28ebc12428f8e38683fdb23 to your computer and use it in GitHub Desktop.
Minio presignedPostPolicy
This file contains 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 Minio = require('minio') | |
var s3Client = new Minio({ | |
endPoint: 'localhost', | |
accessKey: '991OQNY5DUSYGFORMKRX', | |
secretKey: 'Gi2CK8DKIAZPoyRtAXDx33xdJ6IzorEzU0j30F5j', | |
secure: false, | |
port: 9000 | |
}); | |
// Construct a new postPolicy. | |
var policy = s3Client.newPostPolicy() | |
// Set the object name my-objectname. | |
policy.setKey("100.pdf") | |
// Set the bucket to my-bucketname. | |
policy.setBucket("signups") | |
var expires = new Date | |
expires.setSeconds(24 * 60 * 60 * 10) //10 days | |
policy.setExpires(expires) | |
policy.setContentLengthRange(1024, 1024*1024) // Min upload length is 1KB Max upload size is 1MB | |
s3Client.presignedPostPolicy(policy, function(e, urlStr, formData) { | |
if (e) console.log("Error: ",e) | |
var curl = [] | |
curl.push(`curl ${urlStr}`) | |
for (var key in formData) { | |
if (formData.hasOwnProperty(key)) { | |
var value = formData[key] | |
curl.push(`-F ${key}=${value}`) | |
} | |
} | |
// Print curl command to upload files. | |
curl.push('-F file=@<FILE>') | |
console.log("curl: ",curl.join(' ')); | |
//"curl http://localhost/signups -F key=100.pdf -F bucket=signups -F x-amz-date=20160525T115528Z -F x-amz-algorithm=AWS4-HMAC-SHA256 -F x-amz-credential=991OQNY5DUSYGFORMKRX/20160525/us-east-1/s3/aws4_request -F policy=eyJjb25kaXRpb25zIjpbWyJlcSIsIiRrZXkiLCIxMDAucGRmIl0sWyJlcSIsIiRidWNrZXQiLCJzaWdudXBzIl0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMTAyNCwxMDQ4NTc2XSxbImVxIiwiJHgtYW16LWRhdGUiLCIyMDE2MDUyNVQxMTU1MjhaIl0sWyJlcSIsIiR4LWFtei1hbGdvcml0aG0iLCJBV1M0LUhNQUMtU0hBMjU2Il0sWyJlcSIsIiR4LWFtei1jcmVkZW50aWFsIiwiOTkxT1FOWTVEVVNZR0ZPUk1LUlgvMjAxNjA1MjUvdXMtZWFzdC0xL3MzL2F3czRfcmVxdWVzdCJdXSwiZXhwaXJhdGlvbiI6IjIwMTYtMDYtMDRUMDU6MjU6MDAuNTIwWiJ9 -F x-amz-signature=df776dff89bfd7804982780478c755e561b76dffc538cf4017c03a26f724a4be -F file=@<FILE>" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment