Ruby on rails @回形针gem中的内容类型返回不同的值

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

在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>>}}}
"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类型,但只是不同的操作系统

我正在使用:

  • 轨道3
  • 回形针'4.3.2'
  • HTTP规范声明

    当消息中包含一个实体主体时,该主体的数据类型通过头字段Content-type和Content-Encoding确定。这些定义了两层有序编码模型:

    实体主体:=内容编码(内容类型(数据))内容类型 指定基础数据的媒体类型。内容编码可以 用于指示应用于 数据,通常用于数据压缩,是一种属性 请求的资源的名称。没有默认编码

    任何包含实体正文的HTTP/1.1消息都应该包含 内容类型标题字段定义该正文的媒体类型。如果和 仅当“内容类型”字段未给出媒体类型时 接收者可以通过检查介质类型来猜测介质类型 用于标识用户的URI的内容和/或名称扩展名 资源。如果媒体类型仍然未知,则收件人应 将其视为类型“应用程序/八位字节流”

    在您的情况下,可能会发生这种情况,因为发送/上载文件的服务器无法确定文件的类型,因为发送文件时浏览器可能没有在HTTP消息中设置内容类型


    这取决于您使用的浏览器和操作系统。windows上的浏览器可能未设置内容类型。

    例如,CSV也会遇到这种情况。在安装和未安装Excel时,您甚至可以为Windows计算机获取不同的内容类型。因此,如果您将回形针配置为进行内容类型验证或防止内容类型欺骗,则需要处理所有这些
    text/plain
    text/csv
    text/逗号分隔值
    application/vnd.ms excel