Skip to content

Instantly share code, notes, and snippets.

@devgeeks
Created November 28, 2012 05:11
Show Gist options
  • Save devgeeks/4159151 to your computer and use it in GitHub Desktop.
Save devgeeks/4159151 to your computer and use it in GitHub Desktop.
S3 direct upload policy generator
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