Regular expression for zip file

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
    
asked by anonymous 15.12.2016 / 18:24

1 answer

1

You have 2 errors in your code:

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

  • Modify the line with has_attached_file: zip_file ... removing post-processing settings from images
  • 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
    
        
    02.01.2017 / 16:38