Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip process images only

I would like to use a single file-field for multiple formats. It was my understanding that Paperclip was smart enough to only scale images and leave other formats alone, but this doesn't seem to work for flv's (which returns imagemagick/identify-errors). Is there any way to help Paperclip a bit and explicitly setup specific formats to scale?

UPDATE: Apparently, these errors are prevented with :whiny=>false (thanks fl00r), which works fine for regular uploads. However, what I'm trying to do here is uploading the file by FTP, and later on create a new record by code with a File.new([:path]) in the attachment-parameter. This works like a charm for images, but the :whiny=>false-trick won't do it anymore. Does anyone has any tips on this?

like image 682
Jpunt Avatar asked Mar 13 '11 13:03

Jpunt


People also ask

What is Paperclip Rails?

Paperclip is an easy file attachment library for Rails Applications. Attached files are saved to the file system, database or cloud and referenced in the browser by an easily understandable specification.

What is a paperclip file?

Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible.


1 Answers

set :whiny option to false:

has_attached_file :my_attach, :whiny => false ...

it won't help peparclip to process images only, but it won't throw errors if processing failed

UPD

Processing for images only:

has_attached_file :file, 
  :styles => lambda{ |a| ["image/jpeg", "image/png"].include?( a.content_type ) ? { :small => "90x90#" } : {}  }

where you can add as more as you like content types into ["image/jpeg", "image/png"] array

like image 65
fl00r Avatar answered Oct 22 '22 22:10

fl00r