problem in file format validation with Gem Paperclip 5.1.0, Rails 5

Asked

Viewed 61 times

1

Model

has_attached_file :foto
validates_attachment_content_type :foto, content_type: /\Aimage\/.*\z/

Log error

Command :: file -b --mime "C:/Users/conta/AppData/Local/Temp/66c9eed121277d8be2df09ce25c4687a20171106-5872-1j1pihz.jpg"
[paperclip] Content Type Spoof: Filename foto.jpg (image/jpeg from Headers, ["image/jpeg"] from Extension),content type discovered from file command: . See documentation to allow this combination.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • See https://github.com/thoughtbot/paperclip/issues/1429 this link might help you.

1 answer

0

If you want to disable spoofing Protection, create the file:

config/initializers/paperclip_media_type_spoof_detector_override.Rb

And add to it the code:

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end

Browser other questions tagged

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