Skip to content

Instantly share code, notes, and snippets.

@bastien
Created August 18, 2011 15:10
Show Gist options
  • Save bastien/1154270 to your computer and use it in GitHub Desktop.
Save bastien/1154270 to your computer and use it in GitHub Desktop.
Working S3 Policy
bucket = ENV['S3_BUCKET']
access_key = ENV['S3_KEY']
secret = ENV['S3_SECRET']
key = "temp/"
content_type = "application/pdf"
expiration = 5.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
max_filesize = 500.megabytes
acl = 'public-read'
policy = Base64.encode64(
"{'expiration': '#{expiration}',
'conditions': [
{'bucket': '#{bucket}'},
['starts-with', '$key', '#{key}'],
{'acl': '#{acl}'},
{'Content-Type': '#{content_type}'},
{'Content-Disposition': 'attachment'},
['starts-with', '$Filename', ''],
['eq', '$success_action_status', '201']
]}
").gsub(/\n|\r/, '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment