Error uploading files without images using paperclip in rails 4.2

I am getting this error when uploading no image files through a paperclip.

Paperclip error - NotIdentifiedByImageMagickError

Here is my model code:

has_attached_file :attachment, :styles => { :medium => "236x236>", :thumb => "150x150>", :large => "1000x500" }


Here is a version of my gems: paperclip (4.2.1) activemodel (>= 3.0.0) activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types

It works great if I remove styles from the model. But I also need to resize the images.


source to share

2 answers

You need to remove styles from the model. The error is due to the fact that when uploading a file without an image, paperclip sends that file to imageMagick to be resized to fit the specified style. Since the file is not an image file, so imageMagick was unable to convert the file to the specified resolution and the system crashed.

You can group fields for images and attachments without images.

has_attached_file :image_attachment, :styles => { :medium => "236x236>", :thumb => "150x150>", :large => "1000x500" }
has_attached_file :attachment


In the Image Attachment field, specify styles and do not specify styles for attachments without an image.



Try using a model hook before_post_process

. This allows you to change or cancel image processing. From the example posted here

if you return false (in particular - returning zero is not the same) in the before_filter, the post-processing step will stop.

class Message < ActiveRecord::Base
  has_attached_file :asset, styles: {thumb: "100x100#"}

  before_post_process :skip_for_audio

  def skip_for_audio
    ! %w(audio/ogg application/ogg).include?(asset_content_type)




All Articles