Can't download zip files with rubies on rails and copy paperclip

I am working on rails web app. Just created and prepared some models and stuff. The app is very simple. But now I am having a problem setting up the paperclip gem to add attachments to the model. Almost everything works fine, like attaching images / jpg or even PDF.

But I cannot download the zip files. I tried different zip files but I always get: "Attached paperclip :: Errors :: NotIdentifiedByImageMagickError"

This is my model:

class Order < ActiveRecord::Base
  has_attached_file :attachment, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :attachment, :content_type => ["application/pdf", "application/zip", "application/x-zip", "application/x-zip-compressed","application/octet-stream","image/jpg","image/png"]
  belongs_to :client
  has_one :status
end

      

I am developing on Mac (Yosemite) by installing imagemagick through brew and using SQLite.

I added this to my Gemfile:

gem "paperclip", "~> 4.2"
gem 'cocaine', '~> 0.5.4'

      

I've been doing some research on google in the last hours and a lot of people are struggling with paperclip, but I haven't found anyone who has problems downloading zip files.

Can someone help here. Thanks to

+3


source to share


1 answer


ImageMagick cannot read .zip files. See Accepted File Types here:

http://www.imagemagick.org/script/formats.php

If you are trying to create a thumbnail from a zip file, ImageMagick should fail every time.



Try adding this to your model:

before_post_process :skip_for_zip

def skip_for_zip
   ! %w(application/zip application/x-zip).include?(asset_content_type)
end

      

Then your application won't try to process zip files as images

+3


source







All Articles