我正在尝试使用bootstrap验证器验证表单,但文件验证不正常,这是我的代码:
cv: {
validators: {
file: {
extension: 'doc,docx,pdf,zip,rtf',
type: 'application/pdf,application/msword,application/rtf,application/zip',
maxSize: 5120 * 5120 * 5120 * 5120 * 5120, // 5 MB
message: 'The selected file is not valid, it should be (doc,docx,pdf,zip,rtf) and 5 MB at maximum.'
},
notEmpty: {
message: 'CV is required.'
}
}
},
所需的文件扩展名是doc,docx,pdf,rtf,zip,如上所示,但它只接受3个扩展名:doc,rtf,pdf ...那么我的代码中的错误在哪里?
答案 0 :(得分:5)
你错过了DOCX mime类型:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
所以你的代码应该是这样的:
file: {
extension: 'doc,docx,pdf,zip,rtf',
type: 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/rtf,application/zip',
maxSize: 5*1024*1024, // 5 MB
message: 'The selected file is not valid, it should be (doc,docx,pdf,zip,rtf) and 5 MB at maximum.'
},
请参阅此fiddle example。