Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

ruby on rails - 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! `

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally! this helped me!!!

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...