簡體   English   中英

回形針進行內容類型驗證失敗

[英]content-type validation with paperclip fails

我正在嘗試使用回形針上傳.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'

我認為您的內容類型驗證應如下所示:

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

要么

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

從log content_type="audio/x-xm" ,對於內容類型驗證回形針,使用regexp可以在rubular中進行檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM