Created
November 28, 2012 05:11
-
-
Save devgeeks/4159151 to your computer and use it in GitHub Desktop.
S3 direct upload policy generator
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
require 'base64' | |
require 'openssl' | |
require 'digest/sha1' | |
policy_document = '{"expiration": "2015-01-01T00:00:00Z", | |
"conditions": [ | |
{"bucket": "BUCKET_NAME_HERE"}, | |
["starts-with", "$key", "FOLDER_NAME_HERE/"], | |
{"acl": "public-read"}, | |
["starts-with", "$Content-Type", "image/"], | |
["content-length-range", 0, 2048576] | |
] | |
}' | |
aws_secret_key = 'SECRET_KEY_HERE' | |
policy = Base64.encode64(policy_document).gsub("\n","") | |
signature = Base64.encode64( | |
OpenSSL::HMAC.digest( | |
OpenSSL::Digest::Digest.new('sha1'), | |
aws_secret_key, policy) | |
).gsub("\n","") | |
puts "" | |
puts policy | |
puts "" | |
puts signature | |
puts "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment