Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails direct upload to Amazon S3 using Activeadmin + Paperclip

I am using Activeadmin and Paperclip to make images upload on my Rails app. When I try to upload big files to S3 the timeout error occurs, so I have to implement the direct upload to S3.

Does anyone know how can I make it? I could't figure it out...

like image 334
Henrique Amaral Avatar asked Aug 29 '14 20:08

Henrique Amaral


2 Answers

There is a really nice article I've used when was first time setting up the AA+s3+Paperclip.

It has decent explanations + example app on Github, so you can check it live.

In AA the form would look something like this:

form multipart: true do |f|
  # f.semantic_errors *f.object.errors.keys
  f.inputs do
    f.input :image_name #or whatever field is called
  end
    f.has_many :attachments do |a|
      if a.object.persisted?
        link_to image_tag(a.object.encoded_url, class: 'image-preview'), a.object.encoded_url, target: "_blank"
      else
        a.inputs do
          a.s3_file_field(:attachment, as: :file, class: 'js-s3_file_field')
        end +
        a.inputs do
          a.input(:s3_url, as: :hidden, input_html: { class: "s3_url" })
        end
      end  
    end
  f.actions
end
like image 140
Andrey Deineko Avatar answered Nov 10 '22 04:11

Andrey Deineko


The answer appears to be in the comments. Thanks Andrey for the tutorial link.

http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and

like image 27
jmontross Avatar answered Nov 10 '22 05:11

jmontross