ruby on rails - How to save RMagick processed image using Paperclip without writing to a file -


i have been trying upload file (output of rmagick processing ) s3 using paperclip. keep getting error

no handler found http://upload.wikimedia.org/wikipedia/commons/thumb/4/48/ebay_logo.png/800px-ebay_logo.png=>800px-ebay_logo.png png 800x349 800x349+0+0 directclass 8-bit 37kb

basically, in system - user uploads logo using external url, process logo , trim whitespace , upload s3 system. have been using temp file middle man, want directly:

in model, this:

  def fetch_and_trim_logo     puts "logo #{logo}"         if logo_changed?          response = restclient.get logo          if  response.code == 200             img = magick::image::read(logo)[0]             puts "this image #{img.columns}x#{img.rows} pixels"             trimmed_img = img.trim             puts "trimmed image #{trimmed_img.columns}x#{trimmed_img.rows} pixels"             temp_file = tempfile.new(["trimmed_image",".png"])             trimmed_img.write("png:" + temp_file.path)             my_asset = visitor.user.my_assets.new             my_asset.uploaded_file = temp_file             my_asset.save          end         end   end 

my my_asset model has paperclip setup, so:

class myasset<activerecord::base --- ---  has_attached_file :uploaded_file    attr_accessible :uploaded_file   validates_attachment_size :uploaded_file, :less_than=>5.megabyte   has_attached_file :picture,     :styles => { :thumb => "300x300#" },     :default_url => "//#{env['cloudfront_url']}/assets/picture_missing.png" end 

this method works! when change

    my_asset = visitor.user.my_assets.new     my_asset.uploaded_file = temp_file      my_asset.save 

to

    my_asset = visitor.user.my_assets.new     my_asset.uploaded_file = trimmed_img     my_asset.save 

where trimmed_img output of rmagick processing, error "no handler found"

any ideas how fix this?

okay, solution change magic image object file object before uploading paperlip

so,

processed_image = stringio.open(trimmed_img.to_blob) 

then upload processed image directly paperclip


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -