class UniversalS3Uploader::ViewHelper::UploaderHelper
Public Class Methods
new(policy_name)
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 10 def initialize(policy_name) @config = YAML.load_file("#{Rails.root.to_s}/config/amazon.yml") set_policy(policy_name) set_bucket end
Public Instance Methods
bucket()
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 70 def bucket @bucket end
div_tag(name, value)
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 40 def div_tag(name, value) "<div class='#{name}' data-value='#{value}'></div>" end
policy_encoded()
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 78 def policy_encoded Base64.encode64(@policy.to_json).gsub("\n","") end
set_bucket()
click to toggle source
extract bucket name
# File lib/universal_s3_uploader/view_helper.rb, line 26 def set_bucket @policy['conditions'].each do |condition| if condition.class == Hash && condition.keys.first == 'bucket' @bucket = condition.values.first return end end raise 'No bucket name in policy Exception' end
set_policy(policy_name)
click to toggle source
set expiration time
# File lib/universal_s3_uploader/view_helper.rb, line 17 def set_policy(policy_name) @policy = @config[policy_name] @policy['conditions'] << ["starts-with", "$Filename", ""] # for Flash upload if @policy['expiration'] == '' || @policy['expiration'].nil? @policy['expiration'] = 1.hour.from_now.gmtime.iso8601 end end
signature()
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 82 def signature Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @config['secret_access_key'], policy_encoded)).gsub("\n","") end
url()
click to toggle source
# File lib/universal_s3_uploader/view_helper.rb, line 74 def url "http://#{@bucket}.s3.amazonaws.com" end