I have a Rails 3 app using Paperclip 2.3.8. I have the following specified in my model:
validates_attachment_content_type :file,
:content_type => ['image/jpeg', 'image/png', 'image/gif',
'image/pjpeg', 'image/x-png'],
:message => 'Not a valid image file.'
But, when I test a bogus upload, instead of "Not a valid image file." I get this weird error message:
/var/folders/cs/cs-jiL3ZH1WOkgLrcqa5Ck+++TI/-Tmp-/stream20110404-43533-vm7eza.pdf
is not recognized by the 'identify' command.
Any ideas what's going wrong here??
-- EDIT --
For what it's worth I have already covered the ImageMagick/Rmagick steps from the similar question mentioned in the comments (Thanks fl00r!).
One thing that occurs to me (now that I'm on the track of it being an ImageMagick error) is that I have a watermark processor on this image attachment.
So, maybe it's trying to do the watermark processor before it tries to validate and that is where the error message is coming from?
-- EDIT --
I tried removing the processor and that didn't change the error message... so, not sure what to try next.
-- EDIT --
:) Here's the whole model, as requested.
require 'paperclip_processors/watermark'
class Attachment < ActiveRecord::Base
# RELATIONSHIPS
belongs_to :photo
belongs_to :user
has_attached_file :file,
:processors => [:watermark],
:styles => {
:full => "960",
:half => "470",
:third => "306",
:fourth => "225",
:fifth => "176x132#",
:tile => "176x158>",
:sixth => "145x109#",
:eighth => "106x80#",
:tenth => "87x65#",
:marked => { :geometry => "470",
:watermark_path => "#{Rails.root}/public/images/watermark.png",
:position => 'Center' }
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "photos/:user_id/:id/:username_:id_:style.:extension"
# VALIDATIONS
validates_attachment_presence :file
validates_attachment_content_type :file,
:content_type => ['image/jpeg', 'image/png', 'image/gif',
'image/pjpeg', 'image/x-png'],
:message => 'Not a valid image file.'
validate :file_dimensions, :unless => "errors.any?"
# CUSTOM VALIDATIONS
def file_dimensions
dimensions = Paperclip::Geometry.from_file(file.to_file(:original))
self.width = dimensions.width
self.height = dimensions.height
if dimensions.width < 1600 && dimensions.height < 1600
errors.add(:file,'Width or height must be at least 1600px')
end
end
# MAINTENANCE METHODS
def self.orphans
where( :photo_id => nil )
end
end