回形针进行内容类型验证失败

卢卡德

我正在尝试使用回形针上载应该具有mime类型的.xm文件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'
绿色的

我认为您的内容类型验证应如下所示:

validates_attachment_content_type : song, :content_type => /\Aaudio/

或者

validates_attachment_content_type :song, :content_type => /^audio\/(x-xm)/

从日志中content_type="audio/x-xm",对于内容类型验证Paperclip,使用regexp可以在rubular中进行检查

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章