Mongoid-peperclip [回形针]内容类型欺骗:错误 [英] Mongoid-peperclip [paperclip] Content Type Spoof: Error
问题描述
我需要通过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
中,我添加此行
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' }
然后更改为此
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'
这也没有帮助.然后我发现有人建议这样做
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
但是我应该在哪里做呢?在哪个文件中?在哪个目录? (我正在使用Rails 4.0) 如果有人知道如何解决此错误,请告诉我!谢谢! `
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! `
推荐答案
最后!这帮助了我!!!
Finally! this helped me!!!
#config/initilizers/paperclip.rb
require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end
这篇关于Mongoid-peperclip [回形针]内容类型欺骗:错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!