ruby-on-railsmongoidpaperclipspoof

Mongoid-peperclip [paperclip] Content Type Spoof: Error


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! `


Solution

  • Finally! this helped me!!!

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