ruby-on-rails - Paperclip S3 下载远程图片

标签 ruby-on-rails amazon-s3 paperclip

如何下​​载远程图像(http 协议(protocol),url 在 image_remote_url 属性中)并通过 Paperclip 将其保存为 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/

我已经在我自己的网站上成功实现了它。

关于ruby-on-rails - Paperclip S3 下载远程图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2150196/

相关文章:

ruby-on-rails - Ruby on Rails 中的动态路由设置,如 Facebook

amazon-web-services - 如何使用 Cloudfront 设置 AWS Elastic Beanstalk 用于 PHP Stack 上的图像和视频托管

linux - 如何用 jenkins 动态 build_number 替换 efs 文件/代码中的 ${BUILD_NUMBER} 变量

ruby-on-rails - 我无法安装回形针

ruby-on-rails-4 - 如何使用 StringIO 设置 content_type 以使用 PaperClip 上传到 S3

css - 我如何找出哪种样式覆盖另一种样式?

ruby-on-rails - bundle 和 bundle 更新有什么区别?

javascript - 在浏览器中更改渲染工具包

php - Symfony 2 - 在 Amazon S3 上上传图像的最佳实践

ruby-on-rails - 为什么我在部署时出现 Paperclip::CommandNotFoundError 而不是在我的本地?