7

我使用Activeadmin和Paperclip在我的Rails應用上進行圖像上傳。當我嘗試將大文件上傳到S3時發生超時錯誤,所以我必須實現直接上載到S3。Rails直接使用Activeadmin + Paperclip上傳到Amazon S3

有誰知道我該怎麼做?我無法弄清楚......

+0

http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and – 2014-08-29 21:55:41

回答

3

有我的時候是第一次設置的AA+s3+Paperclip使用really nice article

它有不錯的解釋+ example app on Github,所以你可以現場檢查它。

在AA形式會是這個樣子:

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 
+0

我不知道爲什麼,但我遇到了驗證直接url的正則表達式的問題,它是: 'DIRECT_UPLOAD_URL_FORMAT =%r {\ Ahttps:\/\/s3 \ .amazonaws \ .com \/myapp# {!Rails.env.production? ? 「\\ - #{Rails.env}」:''} \ /(? uploads \ /.+ \ /(?。+))\ z} .freeze' 您有任何問題嗎? – 2015-01-30 19:06:16

+0

@HenriqueAmaral我沒有.. – 2015-02-03 07:48:54