Skip to content

Instantly share code, notes, and snippets.

@lporras
Created May 27, 2014 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lporras/3696fdaa837c429fb99a to your computer and use it in GitHub Desktop.
Save lporras/3696fdaa837c429fb99a to your computer and use it in GitHub Desktop.
upload direct s3 helpers
# Helpers
def uploader
@uploader ||= ImageUploader.new
end
def policy
conditions = [
["starts-with", "$utf8", ""],
# Change this path if you need, but adjust the javascript config
["starts-with", "$key", "uploads"],
["starts-with", "$filename", ""],
{ "bucket" => "neufert-tmp-cdn.archdaily.net" },
{ "acl" => uploader.acl }
]
policy = {
# Valid for 3 hours. Change according to your needs
'expiration' => (Time.now.utc + 3600 * 24).iso8601,
'conditions' => conditions
}
Base64.encode64(JSON.dump(policy)).gsub("\n","")
end
def signature
Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
uploader.aws_secret_access_key, policy
)
).gsub("\n","")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment