0

Excuse me I am using paperclip. so when i attachment a file diferent to image (when i don´t upload jpeg,gif or png example zip) show this error:

* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.
* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.
* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.

which is the locale tree path for this error? or which are the locale tree path for paperclip error.

NOTE: I am talking about i18n locale (translate)

thanks in advance

maxiperez
  • 1,470
  • 2
  • 20
  • 40
  • Excuse if you need more information comment this post. – maxiperez Mar 14 '11 at 18:31
  • 1
    check [this](http://stackoverflow.com/questions/1996102/rails-paperclip-and-passenger-is-not-recognized-by-the-identify-command) out – Pizzicato Mar 14 '11 at 18:37
  • thanks. However i search locale (I18n) – maxiperez Mar 14 '11 at 18:46
  • First, that error comes from ImageMagick, not Paperclip. Second, you're uploading RAR files to an image processor, why? Third, Pizzicato's link points to the correct answer. – jenjenut233 Mar 14 '11 at 19:12
  • 1
    @jenjen Users do weird things - it's hardly uncommon to test for edge cases of unexpected user interaction. That's like saying "Why did you try entering words into the phone field? users won't do that!" – nzifnab Mar 14 '11 at 19:31

1 Answers1

1

I don't know about the i18n translation path for this, but if you don't want users to upload non-image file types you should use the validates_attachment_content_type validator that paperclip gives you:

validates_attachment_content_type :attachment, /^image.*/, :message => "Your error message"

Which will generate a sane error for the user instead of the cryptic ImageMagick one. Alternatively, if you want users to be able to upload any file type, but style images a certain way, you can fix your problem like this:

has_attached_file :attachment, :styles => {:thumbnail => ["89x67!", :jpg]}
before_post_process :image?

def image?
  !!(attachment_content_type =~ /^image.*/)
end

This will make it so that all images that get uploaded will also generate an 89x67 sized thumbnail, but if it's not an image type it will skip the processing because image? will return false, and the post_process will not execute (but the file will still be uploaded).

This adds the benefit of being able to say asset.image? later on in a view or something and deciding whether to render it within an image_tag, or as a direct link (just for example).

nzifnab
  • 15,876
  • 3
  • 50
  • 65
  • what is the /^image.*/ parameter? – maxiperez Mar 15 '11 at 15:24
  • excuse me, the validator of paperclip work but the continue showing the imageMagick error – maxiperez Mar 15 '11 at 15:27
  • Thanks. Now i test your solution. this is very good. I don´t know about before_post_process. Again Thank you. – maxiperez Mar 15 '11 at 15:46
  • @maxiperez that parameter can either be an array, or a single value of allowed content types. Each value can be either a regular expression, or an exact-match string (in this case I chose regular expression to match for image filetypes). Documentation for it is here: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/ClassMethods#validates_attachment_content_type-instance_method -- Also, I'm glad you were able to figure it out :) – nzifnab Mar 15 '11 at 16:18