Created
May 27, 2014 20:34
-
-
Save lporras/3696fdaa837c429fb99a to your computer and use it in GitHub Desktop.
upload direct s3 helpers
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
# 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