Mongoid-peperclip 内容类型欺骗:错误

我需要通过mongoid-paperclip上传一些大型CSV文件,我收到错误Uploaded file2 my_file has an extension that does not match its contents 。 在终端中我可以看到此错误为[paperclip] Content Type Spoof: my_file.csv (["text/csv", "text/comma-separated-values"]), content type discovered from file command: application/octet-stream. See documentation to allow this combination. 好吧,我将validation设置为do_not_validate_attachment_file_type :my_file它没有帮助相同的错误。 在application.rb我添加了这一行

 Paperclip.options[:content_type_mappings] = { jpeg: 'image/jpeg', jpg: 'image/jpeg' } 

然后改为这个

 Paperclip.options[:content_type_mappings] = { csv: 'text/csv'} 

它也没有帮助,同样的错误Uploaded file2 my_file has an extension that does not match its contents 。 然后我将validation更改为validates_attachment_content_type:my_file,:content_type =>’text / csv’它也没有帮助。 然后我发现有人建议这样做

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

但我应该在哪里这样做? 在哪个文件? 在哪个目录? (我正在使用rails 4.0)如果有人知道如何解决此错误,请告诉我! 谢谢! `

最后! 这帮了我!!!

 #config/initilizers/paperclip.rb require 'paperclip/media_type_spoof_detector' module Paperclip class MediaTypeSpoofDetector def spoofed? false end end end 
Interesting Posts