【发布时间】:2014-08-02 09:10:53
【问题描述】:
我正在尝试使用回形针上传 .xm 文件,该文件的 mime 类型应为 audio/x-mod。
我通过设置以下选项将回形针配置为允许此配置:
Paperclip.options[:content_type_mappings] = {
xm: "audio/x-mod"
}
附件字段的验证如下所示:
validates_attachment :song, presence: true,
content_type: { content_type: ["audio/x-mod"] },
size: { in: 0..128.kilobytes }
每当我尝试上传 mime 类型为 audio/x-mod 回形针的 .xm 文件时,都会收到错误 Song content type is invalid。
当我将有效的内容类型指定为 [/.+/] 时,它可以工作。
我错过了什么吗?这可能是回形针检查内容类型的错误吗?有什么方法可以查看回形针认为文件的内容类型是什么?
Started POST "/mods" for 127.0.0.1 at 2014-08-02 11:28:56 +0200
Processing by ModsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"FhBvyd8jOapcjONk8kyOgGE/oOZPA+sDBJxr/w3zUG0=", "mod"=>{"title"=>"Girl Next Door", "release(1i)"=>"2014", "release(2i)"=>"8", "release(3i)"=>"2", "song"=>#<ActionDispatch::Http::UploadedFile:0x00000000e763c8 @tempfile=#<Tempfile:/tmp/RackMultipart20140802-1742-wujc7n>, @original_filename="Wiklund_-_Girl_next_door.xm", @content_type="audio/x-xm", @headers="Content-Disposition: form-data; name=\"mod[song]\"; filename=\"Wiklund_-_Girl_next_door.xm\"\r\nContent-Type: audio/x-xm\r\n">}, "commit"=>"Save"}
Command :: file -b --mime '/tmp/d437374435a48a211b1f7b9e585c4c2d20140802-1742-1259ddt.xm'
(0.1ms) begin transaction
Command :: file -b --mime '/tmp/d437374435a48a211b1f7b9e585c4c2d20140802-1742-1e5e5sn.xm'
【问题讨论】: