Created
April 17, 2014 04:22
-
-
Save ryantownsend/10952674 to your computer and use it in GitHub Desktop.
Patches CarrierWave Direct to fix signature not matching errors, as per https://github.com/dwilkie/carrierwave_direct/pull/128
This file contains hidden or 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
# config/initializers/carrierwave_direct.rb | |
require "carrierwave_direct" | |
module CarrierWaveDirect | |
module SignatureFixMonkeyPatch | |
def policy(options = {}) | |
options[:expiration] ||= upload_expiration | |
options[:min_file_size] ||= min_file_size | |
options[:max_file_size] ||= max_file_size | |
@policy ||= generate_policy(options) | |
end | |
def clear_policy! | |
@policy = nil | |
end | |
private | |
def generate_policy(options) | |
conditions = [ | |
["starts-with", "$utf8", ""], | |
["starts-with", "$key", key.sub(/#{Regexp.escape(FILENAME_WILDCARD)}\z/, "")] | |
] | |
conditions << ["starts-with", "$Content-Type", ""] if will_include_content_type | |
conditions << {"bucket" => fog_directory} | |
conditions << {"acl" => acl} | |
if use_action_status | |
conditions << {"success_action_status" => success_action_status} | |
else | |
conditions << {"success_action_redirect" => success_action_redirect} | |
end | |
conditions << ["content-length-range", options[:min_file_size], options[:max_file_size]] | |
Base64.encode64( | |
{ | |
'expiration' => Time.now.utc + options[:expiration], | |
'conditions' => conditions | |
}.to_json | |
).gsub("\n","") | |
end | |
end | |
end | |
CarrierWaveDirect::Uploader.send(:include, CarrierWaveDirect::SignatureFixMonkeyPatch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment