项目新加的需求,需要判断上传图片的宽高,查了一下antd-upload组件貌似不支持这个查询,因此需要使用外部的API,直接上代码:beforeUpload 方法
handleBeforeUpload = async (file, fileList) => {
const {fileMinSize = 0,fileMinWH,fileMaxWH, fileMaxSize = 50,uploadFormat = '',uploadFormatError = ''} = this.component.props;
const isInRange = ((file.size > (fileMinSize * 1024 * 1024)) && (file.size < (fileMaxSize * 1024 * 1024)));
let isTrueType = true,isFileWH = true;//类型,尺寸
return new Promise((resolve, reject) =>{
//校验格式
if(uploadFormat != ''){
let acceptArr = uploadFormat.split(',');
let fileType = file.name.substring(file.name.lastIndexOf('.'));
if(!acceptArr.includes(fileType)){
isTrueType = false;
thi