here is how you could implement remote loading (and still using paperclip):
Create the class as follows:
require 'open-uri'
OpenURI::Buffer.module_eval {
remove_const :StringMax
const_set :StringMax, 0
}
class RemoteUpload
attr_reader :original_filename, :attachment_data
def initialize(url)
@attachment_data = open(url)
path = self.attachment_data.base_uri.path
@original_filename = File.basename(path).downcase
end
def method_missing(symbol, *args)
if self.attachment_data.respond_to? symbol
self.attachment_data.send symbol, *args
else
super
end
end
end
Edit
You can add a virtual attribute to your model, for example photo_remote_url:
class YourModel < ActiveRecord::Base
attr_accessor :photo_remote_url
def photo_remote_url=(url)
return if url.blank?
self.photo = RemoteUpload.new(url)
end
end
source
share