Welcome Guest | Login

500 internal server error cos of RMagick?

I deployed my first rails app today, which went very easily thanks to the excellent tutorials. But i've had a bit of trouble with RMagick.

The first problem was when i went to a page whose controller referenced a model that uses rmagick. I fixed this by changing

require 'rmagick' to
require 'RMagick'

Everything then seemed to work fine. But now I can't upload images. I get a 500 Internal Server Error, and sometimes there is no error in the prodction.log file... but sometimes there is (i'll include it at the end of my post).


The code in the model is:

class Upload < ActiveRecord::Base
 require 'RMagick'
 require 'base64'
 include Magick
 
 
 validates_format_of :content_type, :with => /^image/, :message => "is not an Image file"
 
 before_create :save_data_to_db

   
 def uploaded_image=(picture_field)
   return if picture_field.blank?

   self.content_type = picture_field.content_type.chomp
   
   @saved_data = picture_field.read
 end
 
 
 private
 #####################################################################################
 # ACTION: save_data_to_db (private)
 # PARAMS: none - but the file data has been previously staored in teh @saved_data instance variable
 # DESC: if the favorite flag hasn't been specified on create then defaults to FALSE
 #####################################################################################
 def save_data_to_db
   #create an image object from the uploaded data stream
   img = Magick::Image::read_inline(Base64.b64encode(@saved_data)).first
   
   #strip out any profile data and exif data
   img.strip!

   #resize to largest required
   img.change_geometry!("800x600>") do |cols, rows, image|
     image.resize!(cols, rows)
   end
   self.file = img.to_blob
   self.file_width = img.columns
   self.file_height = img.rows
   
   #now make the preview thumbnail
   img.change_geometry!("230x200>") do |cols, rows, image|
     image.resize!(cols, rows)
   end
   self.thumb = img.to_blob
   self.thumb_width = img.columns
   self.thumb_height = img.rows

   img = nil
   GC.start
 end
 
 
end



basically, the form chucks the file to the uploaded_image method which checks validates the mime type and saves data into a variable. A filter than calls save_data_to_db to process the image.

By commenting out bits of code, i can see that the server crashes on the first reference to Magick:

img = Magick::Image::read_inline(Base64.b64encode(@saved_data)).first

It works on my dev environment at home fine. And the file is being uploaded in prod because the validatiosn work if i try an upload an excel file.

any ideas?? I need to get this up and running asap - the erst of the site is fine, but a gallery site is no good without uploads!!

thanks!

PRODUCTION LOG error reported:

Processing PrintController#admin (for 87.xxx.xx.92 at 2008-05-29 12:05:03) [POST]
 Session ID: BAh7CDoMY3NyZl9pZCIlZDBiM2E5MGY0MzYyYmM3NjA3MDAzYTc5OTg5ZTE0%0ANDUiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA6DHVzZXJfaWRpBg%3D%3D--7bb79d43b46cf5c0ac3f97b28ff2eafc3560d3d9
 Parameters: {"commit"=>"Upload File", "authenticity_token"=>"46c16f5cfb5a2346f5aff0039fbb09115b87ee46", "action"=>"admin", "upload"=>{"uploaded_image"=>#<File:/tmp/CGI.11286.1>}, "id"=>"131", "controller"=>"print"}


Errno::ECONNRESET (Connection reset by peer):
   /usr/local/lib/ruby/1.8/base64.rb:114:in `write'
   /usr/local/lib/ruby/1.8/base64.rb:114:in `print'
   /usr/local/lib/ruby/1.8/base64.rb:114:in `b64encode'
   /usr/local/lib/ruby/1.8/base64.rb:113:in `scan'
   /usr/local/lib/ruby/1.8/base64.rb:113:in `b64encode'
   /app/models/upload.rb:29:in `save_data_to_db'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:307:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:307:in `callback'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:in `each'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:in `callback'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:225:in `create_without_timestamps'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/timestamp.rb:29:in `create'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2238:in `create_or_update_without_callbacks'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:213:in `create_or_update'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1972:in `save_without_validation'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:934:in `save_without_transactions'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in `transaction'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in `rollback_active_record_state!'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
   /app/controllers/print_controller.rb:214:in `admin'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
   /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
   /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:101:in `process_request'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:149:in `with_signal_handler'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:99:in `process_request'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:77:in `process_each_request'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each_cgi'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:76:in `process_each_request'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:50:in `process!'
   /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:24:in `process!'
   dispatch.fcgi:24

Rendering /home/xxxxxxxxxxxxxxxxx/public/500.html (500 Internal Server Error)

2008-05-29 12:09 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.