上传文件限制文件类型
作者:互联网
const beforeUpload = (file) => { return new Promise((resolve, reject) => { let acceptList = [".xls",".xlsx",".pdf",".doc",".docx",".jpg",".jpeg",".png",".rar",".zip"]; if (file.name.indexOf('.') !== -1) { // 如果存在. let suffixList = file.name.split('.'); let suffix = '.'+suffixList[suffixList.length - 1]; console.log(suffix); if (!acceptList.includes(suffix)) { message.error("禁止上传此类型文件"); return false; } } else { message.error("禁止上传无后缀文件"); return false; } let res = true; if (fileShowList.length > 0) { fileShowList.map((item) => { if (item.name === file.name) { message.error(item.name + '此文件已经上传'); res = false; } }); } const isLt5M = file.size / 1024 / 1024 < 20; if (!isLt5M) { message.error('上传文件不能超过 20MB!'); } if (res && isLt5M) { resolve(); } else { reject(''); } }); };
标签:文件,name,let,file,error,文件类型,message,上传 来源: https://www.cnblogs.com/domin520Jian/p/16401256.html