Mongoid peperclip[回形针]内容类型后台文件:错误



我需要通过mongoid回形针上传一些大的CSV文件,但我遇到了错误CCD_ 1。在终端中,我可以将此错误视为[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.好的,我将验证设置为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。然后,我将验证更改为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

相关内容

最新更新