回形针S3下载远程图片 [英] Paperclip S3 download remote images

查看:184
本文介绍了回形针S3下载远程图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以下载一个远程图像(http协议,URL是在image_remote_url属性),并将其保存为经回形针的附件S3?

How I can download a remote image (http protocol, the url is in the image_remote_url attribute) and save it as an attachment to S3 via Paperclip ?

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一下?

How should the method "fetch_image" look ?

推荐答案

这里有一个链接到一个网页,解释正是你需要的。

Here's a link to a page that explains exactly what you need.

http://trevorturk.word$p$pss.com/2008/12/11/easy-upload-via-url-with-paperclip/

我已经成功地在我自己的网站来实现它。

I've implemented it successfully on my own site.

这篇关于回形针S3下载远程图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆