Ruby on rails @回形针gem中的内容类型返回不同的值
在windows中,我得到:Ruby on rails @回形针gem中的内容类型返回不同的值,ruby-on-rails,ruby-on-rails-3,paperclip,Ruby On Rails,Ruby On Rails 3,Paperclip,在windows中,我得到: @content_type="application/octet-stream" 完整跟踪: "attachments_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x007f7bb52becc8 @original_filename="ms_document.doc", @content_type="application/octet-str
@content_type="application/octet-stream"
完整跟踪:
"attachments_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x007f7bb52becc8 @original_filename="ms_document.doc", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"post[attachments_attributes][0][attachment]\"; filename=\"doc\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20160108-8859-x51qhj>>}}}
"attachments_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x007f7bb5d585d0 @original_filename="ms_document.doc", @content_type="application/msword", @headers="Content-Disposition: form-data; name=\"post[attachments_attributes][0][attachment]\"; filename=\"doc.doc\"\r\nContent-Type: application/msword\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20160108-8859-9m1xgv>>}}}
完整跟踪:
"attachments_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x007f7bb52becc8 @original_filename="ms_document.doc", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"post[attachments_attributes][0][attachment]\"; filename=\"doc\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20160108-8859-x51qhj>>}}}
"attachments_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x007f7bb5d585d0 @original_filename="ms_document.doc", @content_type="application/msword", @headers="Content-Disposition: form-data; name=\"post[attachments_attributes][0][attachment]\"; filename=\"doc.doc\"\r\nContent-Type: application/msword\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20160108-8859-9m1xgv>>}}}
“附件属性”=>{“0”=>{“附件”=>}
问题是,为什么我上传同一个文件时收到了不同的@content\u类型,但只是不同的操作系统
我正在使用:
这取决于您使用的浏览器和操作系统。windows上的浏览器可能未设置内容类型。例如,CSV也会遇到这种情况。在安装和未安装Excel时,您甚至可以为Windows计算机获取不同的内容类型。因此,如果您将回形针配置为进行内容类型验证或防止内容类型欺骗,则需要处理所有这些
text/plain
、text/csv
、text/逗号分隔值
、application/vnd.ms excel
。