views:

330

answers:

1

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

How should the method "fetch_image" look ?

+2  A: 

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

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

I've implemented it successfully on my own site.

jlfenaux