简体   繁体   中英

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...

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM