Paperclip by default try to process every image file to generate thumbnail. But it also try to do it with pdf files, which can be really time consuming task. I tried looking on google and found one solution, but it changes Paperclip methods.
How to disable pdf postprocessing in Paperclip without changing Paperclip sources?
From my current production app, similar to above, but explicitly looks for images (in this case my uploader pretty much accepts any type of file, so I process only images and ignore all others):
before_post_process :is_image?
def is_image?
["image/jpeg", "image/pjpeg", "image/png", "image/x-png", "image/gif"].include?(self.asset_content_type)
end
One solution is to use before_post_process
callback:
# Model with has_attached_file
before_post_process :forbid_pdf # should be placed after line with has_attached_file
private
def forbid_pdf
return false if (data_content_type =~ /application\/.*pdf/)
end
data_content_type
should be changed to corresponding field in your model.
Another solution I came up with is to create custom processor for images in which we should check file type and if it is not pdf run standard processor Paperclip::Thumbnail
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With