0

mongoid-paperclip を介していくつかの大きな CSV ファイルをアップロードする必要があり、エラーが発生して いますUploaded file2 my_file has an extension that does not match its contents。ターミナルでは、このエラーが [OK] として表示され ます。同じエラーには役立たないため[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を使用しています) このエラーを修正する方法を知っている人がいたら教えてください! ありがとうございました!`

4

1 に答える 1

1

ついに!これは私を助けました!!!

#config/initilizers/paperclip.rb
require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end
于 2014-10-02T13:25:14.147 に答える