我正在使用paperclip gem上传文件,我的paperclip gem版本是paperclip-4.1.1。在上传文件时出现问题:
Validation failed: Upload file has an extension that does not match its contents.
我正在尝试上传一个xlsx文件,并且我已经在模型content_type中提到了它。 validates_attachment_content_type :upload_file, :content_type => %w(application/msword application/vnd.ms-office application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet),
:message => ', Only XML,EXCEL files are allowed. '
我不知道为什么会出现这个错误。如果您对此错误有任何想法,请分享。
摘录日志以显示验证失败:
Command :: file -b --mime-type '/tmp/5249540099071db4e41e119388e9dd6220140513-24023-1jlg4zy' [paperclip] Content Type Spoof: Filename file_for_bulk_upload1.xlsx (["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]), content type discovered from file command: . See documentation to allow this combination.
Command :: file -b --mime-type '/tmp/6f19a4f96154ef7ce65db1d585abdb2820140513-24023-tt4u1e' [paperclip] Content Type Spoof: Filename file_for_bulk_upload1.xlsx (["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]), content type discovered from file command:
application/xml
。 - user740584file --mime-type <filename.xlsx>
和mimetype <filename.xlsx>
。 - user740584