2

リモートイメージ(httpプロトコル、URLはimage_remote_url属性にあります)をダウンロードして、ペーパークリップを介してS3への添付ファイルとして保存するにはどうすればよいですか?

class Product < ActiveRecord::Base
  require 'open-uri'
  attr_accessor :image_remote_url
  has_attached_file :photo,
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => ":class/:id/:style.:extension",
    :bucket => "my_bucket",
    :styles => {
      :icon => "32x32#",
  }

  def fetch_image
    # how should this method look ?
  end

end

メソッド「fetch_image」はどのように見えるべきですか?

4

2 に答える 2

6

必要なものを正確に説明しているページへのリンクは次のとおりです。

http://trevorturk.wordpress.com/2008/12/11/easy-upload-via-url-with-paperclip/

私はそれを自分のサイトにうまく実装しました。

于 2010-02-11T13:45:56.847 に答える
2

これがまだあなたに役立つかどうかはわかりませんが、ほんの数時間前にペーパークリップへのプルリクエストで、これを非常に簡単にすることができました。

def set_photo
  self.photo = URI.parse(self.image_remote_url)
end

これにより、ペーパークリップ(バージョン> 3.1.3)で機能するはずです(3.1.3ではなく、その後に続くもの)。

于 2012-07-20T18:01:22.920 に答える