3.0.3
win7,chrome63.0.3239.84
https://codepen.io/LynnHg/pen/YYZdRV
handleBeforeUpload(file) {
const sizeOk = file.size < 1024 * 300;
const typeOk =
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'image/bmp' ||
file.type === 'image/gif';
if (!typeOk) {
message.error('照片格式有误!');
} else {
if (!sizeOk) {
message.error('照片大小超过300K!');
}
}
return sizeOk && typeOk;
}
当上传错误格式的照片,提示格式错误,但不显示任何效果
当上传错误格式的照片,提示格式错误,但界面上显示了"文件上传中"
It will be better to write your issue/comment in English, so more people can understand you.
And this means that more people can help you or benefit from your issue/comment.
See: https://github.com/ant-design/ant-design/issues/4897
这是因为onChange
的回调方法有问题,不能这样写
I think it's a problem, When beforeUpload
retrun false, file
object in callback onChange
should give a right status
.
and if use Promise, reject wont trigger onChange
, but return false does!
if (!typeOk) {
message.error('照片格式有误!');
return false
}
if (!sizeOk) {
message.error('照片大小超过300K!');
return false
}
return true;
Duplicate of #8020
beforeUpload (file) {
const maxFileSize = 2;
const isLtMax = file.size / 1024 / 1024 < maxFileSize;
return new Promise((resolve, reject) => {
if(!isLtMax) {
reject(file);
} else {
resolve(file);
}
});
};
This way will prevent the error file from adding to the fileList.
Most helpful comment
beforeUpload (file) {
const maxFileSize = 2;
const isLtMax = file.size / 1024 / 1024 < maxFileSize;
};
This way will prevent the error file from adding to the fileList.