Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload组件:beforeUpload上传前检查问题 #8779

Closed
LynnHg opened this issue Dec 29, 2017 · 7 comments
Closed

Upload组件:beforeUpload上传前检查问题 #8779

LynnHg opened this issue Dec 29, 2017 · 7 comments
Labels
🐛 Bug Ant Design Team had proved that this is a bug. Inactive

Comments

@LynnHg
Copy link

LynnHg commented Dec 29, 2017

Version

3.0.3

Environment

win7,chrome63.0.3239.84

Reproduction link

https://codepen.io/LynnHg/pen/YYZdRV

Steps to reproduce

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;

}

What is expected?

当上传错误格式的照片,提示格式错误,但不显示任何效果

What is actually happening?

当上传错误格式的照片,提示格式错误,但界面上显示了"文件上传中"

@ant-design-bot
Copy link
Contributor

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: #4897

@infeng
Copy link
Contributor

infeng commented Dec 29, 2017

这是因为onChange的回调方法有问题,不能这样写

@yutingzhao1991 yutingzhao1991 added the 🐛 Bug Ant Design Team had proved that this is a bug. label Dec 29, 2017
@yutingzhao1991
Copy link
Contributor

I think it's a problem, When beforeUpload retrun false, file object in callback onChange should give a right status.

@sponialdy
Copy link

and if use Promise, reject wont trigger onChange, but return false does!

@Cecilxx
Copy link

Cecilxx commented Jan 4, 2018

if (!typeOk) {
   message.error('照片格式有误!');
   return false
} 
if (!sizeOk) {
    message.error('照片大小超过300K!');
    return false
}
return true;

@afc163
Copy link
Member

afc163 commented Feb 11, 2018

Duplicate of #8020

@afc163 afc163 marked this as a duplicate of #8020 Feb 11, 2018
@afc163 afc163 closed this as completed Feb 11, 2018
@iiiok
Copy link

iiiok commented May 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Ant Design Team had proved that this is a bug. Inactive
Projects
None yet
Development

No branches or pull requests

9 participants