확장명이 .txt 인 첨부 파일을 업로드해야하지만 file 명령으로 mime-type "application/octet-stream"으로 평가해야합니다. 파일은 장비에 의해 자동으로 생성되며 업로드하기 전에 파일 이름을 바꾸는 것은 불가능합니다.paperclip 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를 사용했습니다.