我需要通过 mongoid-paperclip 上传一些大型 CSV 文件,但出现错误
Uploaded file2 my_file has an extension that does not match its contents
。在终端中,我可以看到这个错误是
[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)如果有人知道如何解决这个错误,请告诉我!谢谢!`