【发布时间】:2016-04-12 19:17:35
【问题描述】:
在 Windows 中,我得到:
@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>>}}}
在 Linux 中我得到:
@content_type="application/msword"
完整的跟踪:
"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>>}}}
问题是,为什么我在上传相同文件但只有不同操作系统时收到不同的@content_type。
我正在使用:
- 导轨 3
- 回形针'4.3.2'
【问题讨论】:
-
例如,CSV 也会遇到这种情况。在安装和未安装 Excel 时,您甚至可以获得 Windows 计算机的不同内容类型。因此,如果您将回形针配置为进行内容类型验证或防止内容类型欺骗,则需要处理所有这些
text/plain、text/csv、text/comma-separated-values、application/vnd.ms-excel。
标签: ruby-on-rails ruby-on-rails-3 paperclip