rails paperclip content_type 设置以及遇到的问题
问题:
Paperclip xlsx 能通过content type 验证,但xls 不行。
代码如下:
validates_attachment_content_type :file, :content_type => [
"application/pdf",
"image/jpeg",
"image/jpg",
"application/vnd.ms-excel",
"application/msword",
"application/octet-stream",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
]
修改如下,在上面代码中加入application/x-ole-storage 即可
...content_type: [...'application/x-ole-storage'...]
另外可以使用验证后缀的方法:
validates_attachment_file_name :file, matches: [/.pdf$/, /.docx?$/, /.xlsx?$/, /.odt$/, /.ods$/]
rails paper clip农田validating content type application/octet-stream
validates_attachment_content_type :media,
content_type: [
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'video/avi',
'video/mov',
'video/mp4',
'video/x-flv',
'video/3gpp',
'video/quicktime',
'video/x-msvideo',
'video/x-ms-wmv',
'flv-application/octet-stream',
'application/octet-stream',
'video/x-flv',
'video/mpeg',
'video/mpeg4',
'video/x-la-asf',
'video/x-ms-asf'
],
:message => 'file type is not allowed'
参考链接:https://www.py4u.net/discuss/1238188
https://www.py4u.net/discuss/1236086

浙公网安备 33010602011771号