实现限制图片上传格式、尺寸、分辨率的限制
checkImageWH(file, width, height, resolve, reject) {let filereader = new FileReader();filereader.onload = e => {let src = e.target.result;const image = new Image();image.onload = function () {console.log(this.width, this.height)if ((width && this.width < width) || (height && this.height < height)) {if ((width && this.width < height) || (height && this.height < width)) {Modal.error({title: '分辨率请勿小于'+width+'*'+height+'或'+height+'*'+width})reject()} else {resolve();}} else {resolve();}};image.onerror = reject;image.src = src;};filereader.readAsDataURL(file);}
handleBeforeUploads = file => {//限制图片 格式、size、分辨率const that= thisreturn new Promise(function (resolve, reject) {const isJPG = file.type === 'image/jpg';const isJPEG = file.type === 'image/jpeg';const isPNG = file.type === 'image/png';const bigLt2M = file.size / 1024 / 1024 < 5;// console.log(file);if (!(isJPG || isJPEG || isPNG)) {Modal.error({title: '只能上传JPG 、JPEG 、 PNG格式的图片~',});reject()} else if (!bigLt2M) {Modal.error({title: '请误超过5M',});reject()}else{that.checkImageWH(file, 480, 854, resolve, reject)}})};
{fileList.length >= 9 ? null : uploadButton}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!