upload image by url in PaperClip rails



object.upload_image((image_url).gsub!('www.','http://'))

#write this method in model
require 'open-uri'
def upload_image(url)
 begin
  io = open(URI.escape(url))
  if io
   def io.original_filename; base_uri.path.split(‘/’).last; end
   io.original_filename.blank? ? nil : io
   self.image = io
  end
  self.save(false)
 rescue Exception => e
  logger.info “EXCEPTION# #{e.message}”
 end
end
Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: ,
Posted in paperclip, Ruby Little Codes, Ruby on Rails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: