Created
October 19, 2011 14:31
-
-
Save stouset/1298462 to your computer and use it in GitHub Desktop.
Transloadit-Paperclip integration
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
def decode_transloadit_json | |
return unless params[:transloadit].present? | |
# wrap transloadit params in a HashWithIndifferentAccess | |
params[:transloadit] = ActiveSupport::HashWithIndifferentAccess.new( | |
ActiveSupport::JSON.decode params[:transloadit] | |
) | |
# decode parameters from transloadit | |
params[:transloadit][:uploads].first.tap do |history| | |
params[:report].update( | |
:history_file_name => history[:name], | |
:history_file_size => history[:size], | |
:history_content_type => history[:mime], | |
:history_transloadit_id => history[:id].insert(2, '/'), | |
:history_updated_at => Time.parse(params[:transloadit][:start_date]) | |
) | |
end | |
end |
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
has_attached_file :history, YAML::load_file('config/paperclip.yml')[Rails.env] |
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
defaults: &defaults | |
:default_url: '' | |
filesystem: &filesystem | |
:storage: :filesystem | |
:url : /system/attachments/:env/:class/:id/:attachment/:filename | |
:path : ':rails_root/public/system/attachments/:env/:class/:id/:attachment/:filename' | |
s3: &s3 | |
:storage : :s3 | |
:url : ':s3_domain_url' | |
:path : attachments/:attachment/:transloadit_id/:filename | |
:s3_credentials: config/s3.yml | |
:s3_permissions: private | |
:s3_protocol : https | |
development: | |
<<: *defaults | |
<<: *filesystem | |
test: | |
<<: *defaults | |
<<: *filesystem | |
:path: ':tmpdir/:app/attachments/:env/:class/:id/:attachment/:filename' | |
production: | |
<<: *defaults | |
<<: *s3 |
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
Paperclip.interpolates(:env) do |attachment, style| | |
Rails.env | |
end | |
Paperclip.interpolates(:tmpdir) do |attachment, style| | |
Dir.tmpdir | |
end | |
Paperclip.interpolates(:app) do |attachment, style| | |
Rails.application.class::NAME | |
end | |
Paperclip.interpolates(:transloadit_id) do |attachment, style| | |
attachment.instance.send :"#{attachment.name}_transloadit_id" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment