0

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

arthur-net
  • 1,138
  • 1
  • 13
  • 34

1 Answers1

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
cjhveal
  • 5,668
  • 2
  • 28
  • 38
arthur-net
  • 1,138
  • 1
  • 13
  • 34