I struggled with the same problem and decided to completely bypass the carrier wave and simply load directly onto S3 as follows:
$('.post-editor').froalaEditor({ toolbarBottom: true, toolbarButtons: ['bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'insertLink', 'insertImage', 'insertVideo'], imageUploadToS3: { bucket: "<%= @hash[:bucket] %>", region: 's3-us-west-1', keyStart: "<%= @hash[:key_start] %>", callback: function (url, key) {}, params: { acl: "<%= @hash[:acl] %>", // ACL according to Amazon Documentation. AWSAccessKeyId: "<%= @hash[:access_key] %>", // Access Key from Amazon. policy: "<%= @hash[:policy] %>", // Policy string computed in the backend. signature: "<%= @hash[:signature] %>", // Signature computed in the backend. } } })
Configure the initializer in config / initializers / AWS_CONFIG.rb:
AWS_CONFIG = { 'access_key_id' => ENV["S3_ACCESS_KEY"], 'secret_access_key' => ENV["S3_SECRET_KEY"], 'bucket' => 'froala-bucket', 'acl' => 'public-read', 'key_start' => 'uploads/' }
Configure Amazon signature in lib / amazon_signature.rb:
module AmazonSignature extend self def signature Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest.new('sha1'), AWS_CONFIG['secret_access_key'], self.policy ) ).gsub("\n", "") end def policy Base64.encode64(self.policy_data.to_json).gsub("\n", "") end def policy_data { expiration: 10.hours.from_now.utc.iso8601, conditions: [ ["starts-with", "$key", AWS_CONFIG['key_start']], ["starts-with", "$x-requested-with", "xhr"], ["content-length-range", 0, 20.megabytes], ["starts-with", "$content-type", ""], {bucket: AWS_CONFIG['bucket']}, {acl: AWS_CONFIG['acl']}, {success_action_status: "201"} ] } end def data_hash {:signature => self.signature, :policy => self.policy, :bucket => AWS_CONFIG['bucket'], :acl => AWS_CONFIG['acl'], :key_start => AWS_CONFIG['key_start'], :access_key => AWS_CONFIG['access_key_id']} end end
And finally, name it in your PostsController:
before_action :set_hash_for_froala ... def set_hash_for_froala @hash = AmazonSignature::data_hash end
This video was very helpful: http://rubythursday.com/episodes/ruby-snack-23-froala-wysiwyg-saving-images-on-amazon-s3