Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stouset
Created October 19, 2011 14:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stouset/1298462 to your computer and use it in GitHub Desktop.
Save stouset/1298462 to your computer and use it in GitHub Desktop.
Transloadit-Paperclip integration
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
has_attached_file :history, YAML::load_file('config/paperclip.yml')[Rails.env]
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
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