Mongoid-peperclip [paperclip] Content Type Spoof: Error

心已入冬 提交于 2019-12-11 19:59:54

问题


I need to upload some large CSV files via mongoid-paperclip and I am getting error Uploaded file2 my_file has an extension that does not match its contents. In terminal I can see this error as [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. Ok, I set validation as do_not_validate_attachment_file_type :my_file It does not help same error. In application.rb I add this line

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

Then changed to this

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

It also does not help, same error Uploaded file2 my_file has an extension that does not match its contents. Then I changed validation to validates_attachment_content_type :my_file, :content_type => 'text/csv' It also did not help. Then I found some one suggesting to do this

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

But where I should do this? in which file? in which directory? (I am using rails 4.0) If any one knows how to fix this error, please let me know! Thank you! `


回答1:


Finally! this helped me!!!

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


来源:https://stackoverflow.com/questions/26161069/mongoid-peperclip-paperclip-content-type-spoof-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!