Regular expression for zip file

Asked

Viewed 45 times

0

How to add a zip file instead of an image?

    class UploadDatabase < ActiveRecord::Base
        has_attached_file :zip_file, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
        validates_attachment_content_type :zip_file, content_type: /\Aimage\/.*\Z/
    end
  • Which Gem are you using for this?

1 answer

1

There are 2 errors in your code:

  1. The template is configured to post-process the file using imagemagick to generate previews. This is not possible for zip files
  2. Zip files will be refused at the end of upload because the template is configured to accept images.

To correct:

  1. Modify the line with has_attached_file :zip_file... removing image post-processing settings
  2. Modify content-type to allow files with mime type to zip

The code would be:

class UploadDatabase < ActiveRecord::Base

  has_attached_file :zip_file
  validates_attachment_content_type :zip_file,
                                    content_type: [
                                        "application/zip",
                                        "application/x-zip",
                                        "application/x-zip-compressed"
                                    ]
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.