回形针S3下载远程图像
问题描述:
我如何下载远程图像(http协议,URL位于image_remote_url属性中)并通过Paperclip将其保存为S3的附件?回形针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”应该怎么看?
答
下面是一个页面的链接,可以准确解释您需要什么。
http://trevorturk.wordpress.com/2008/12/11/easy-upload-via-url-with-paperclip/
我已经成功地实现了它自己的网站上。
答
我不确定这对你有没有用,但是在几个小时前对回形针的拉取请求中,我设法让这个超级简单。
def set_photo
self.photo = URI.parse(self.image_remote_url)
end
这应该现在在回形针(版本> 3.1.3)(不是3.1.3,但无论之后来)的工作。