[Mongrel] Rails, Mongrel and Rmagick

John Lauck john-subscribed at recaffeinated.com
Thu May 17 09:28:52 EDT 2007


I figured out my problem here, but I don't think it explains the entire
issue.  The problem was that some files where not uploading as image files
and instead the @uploaded_file was a String.  If I check the class of the
file first I can work around the problem.  I still don't think it makes
sense that there are no exceptions thrown.

Here's a simplified look at the code in my rails model.

    if @uploaded_file.class == File || @uploaded_file.class == Tempfile
      begin
        img = Magick::Image::read(@uploaded_file.path).first
        self.data = @uploaded_file.read
        self.attributes = {:data_format => img.format, :height => img.rows,
:width => img.columns, :filesize => img.filesize}
        return true
      rescue
        # there was an error
      end
    end


On 5/16/07, John Lauck <john-subscribed at recaffeinated.com> wrote:
>
> i have a rails app with a form that allows uploading an image file.  I
> take the image file and read it into rmagick to verify that it's an image.
> For some reason I can't catch an exception thrown by rmagick inside the
> app.  After an invalid image file is uploaded the process just hangs.  I
> have to kill mongrel and restart to use the app again.
>
> img = Magick::Image::read(@uploaded_file.path).first
>
> This line above should throw a Magick::ImageMagickError exception.  I've
> confirmed this with a simple ruby script.
>
> I've tried adding breakpoints and as soon as this line is reached there's
> no coming back, even the breakpointer hangs.
>
> I pasted the method from my active record class here:
> http://pastie.caboo.se/62122 .
>
> Does anyone have any ideas?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070517/a9c0198c/attachment.html 


More information about the Mongrel-users mailing list