我需要上傳帶有.txt擴展名的附件,但通過file命令評估MIME類型「application/octet-stream」。該文件是由一臺設備自動生成的,在上傳之前重命名該文件是不可行的。我曾嘗試:回形針5.1內容類型驗證過於嚴格
class Book < ActiveRecord::Base
has_attached_file :excerpt
validates_attachment_content_type :excerpt, content_type: { content_typ: ["text/plain", "application/octet-stream"]}
validates_attachment_file_name :excerpt, matches: [/txt\z/]
end
但我總是得到一個錯誤檢測到的內容類型不匹配推斷內容類型:
Command :: file -b --mime '/tmp/313a40bb0448477e051da1e2cba2c20120161027-19345-lrhf6t.txt'
[paperclip] Content Type Spoof: Filename Sample.txt (text/plain from Headers, ["text/plain"] from Extension), content type discovered from file command: application/octet-stream. See documentation to allow this combination.
該錯誤消息說,在文檔,以尋找一種方式以允許組合,但我一直無法找到任何看起來像解決方法。看到這discussion,但它是爲v4。