Monday, November 21, 2011

Paperclip image upload via URL

by Sandip Ransing 0 comments

Upload image via paperclip via passing URL instead of file upload
# Consider Print instance with image as file attachment class Print < ActiveRecord::Base has_attached_file :image 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 p.image = io end p.save(false) rescue Exception => e logger.info "EXCEPTION# #{e.message}" end end end Text code from console
p = Print.new url = "http://ocdevel.com/sites/ocdevel.com/files/images/rails.png" p.upload_image(url)

blog comments powered by Disqus

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter