Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carrierwave - Error when processing images

The problem is the following error which is thrown on mongoids save! action.

Mongoid::Errors::Validations: Validation failed - Img failed to be processed.
~/.rvm/gems/ruby-1.8.7-p249/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:234:in `fail_validate!'
~/.rvm/gems/ruby-1.8.7-p249/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:75:in `save!'
./app.rb:29:in `POST /upload'

The setup is mostly the following:

require "sinatra"     # 1.1.2
require "mongoid"     # 2.0.0.beta.19
require "rmagick"     # 2.12.2
require "carrierwave" # 0.5.1
require "carrierwave/orm/mongoid"
require 'carrierwave/processing/rmagick'
....


Mongoid.database = Mongo::Connection.new('somehost', 1234).db('test')

class Uploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  storage :file

  def store_dir
    "uploads"
  end

 process :resize_to_fit => [80, 80]
end


class Image
  include Mongoid::Document

  mount_uploader :img, Uploader
end


....

post '/upload' do
  @img = Image.new
  @img.img = params[:file]
  @img.save!
  redirect '/'
end

The glitch is somewhere in the processing:

process :resize_to_fit => [80, 80]

If I remove this line. Everything works as expected.

like image 491
Jonas Avatar asked Feb 23 '11 22:02

Jonas


1 Answers

Ok. I didn't follow the traces deep enough: The problem was a missing jpeg-delegate in ImageMagick. So naturally processing of jpeg-files failed.

The solution was to reinstall ImageMagick from source.

Still it's quite opaque when Mongoid throws an Error which is called from carrierwave because it gets an error from RMagick which was triggered by ImageMagick.

Still. In retrospective it's quite obvious :-)

like image 51
Jonas Avatar answered Sep 30 '22 04:09

Jonas