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 /> to upload unsupported files, method beforeUpload return false, then fileList is mistakenly bleached #8036

Closed
MasonChow opened this issue Oct 27, 2017 · 4 comments
Labels
🐛 Bug Ant Design Team had proved that this is a bug.

Comments

@MasonChow
Copy link

Version

2.13.1

Environment

MAC/WIN chrome 61.0

Reproduction link

https://codepen.io/funya/pen/pdzaRB?&editors=001

Steps to reproduce

Under ver.2.13, when use to upload unsupported files, method beforeUpload return false, then fileList is mistakenly bleached. The same problem is not detected under ver.2.12

What is expected?

Unsupported don't replace and empty the fileList

What is actually happening?

Unsupported files empty the fileList and replace it

@benjycui benjycui added the 🐛 Bug Ant Design Team had proved that this is a bug. label Oct 27, 2017
@benjycui
Copy link
Contributor

benjycui commented Nov 1, 2017

@afc163 after beforeUpload return false, we just pass fileList to developers:

if (result === false) {
this.onChange({
file,
fileList,
});
return false;
} else if (result && (result as PromiseLike<any>).then) {

I think we should concat the fileList with this.state.fileList, just link onStart:

onStart = (file) => {
let targetItem;
let nextFileList = this.state.fileList.concat();
if (file.length > 0) {
targetItem = file.map(f => {
const fileObject = fileToObject(f);
fileObject.status = 'uploading';
return fileObject;
});
nextFileList = nextFileList.concat(targetItem);
} else {
targetItem = fileToObject(file);
targetItem.status = 'uploading';
nextFileList.push(targetItem);
}
this.onChange({
file: targetItem,
fileList: nextFileList,
});
// fix ie progress
if (!(window as any).FormData) {
this.autoUpdateProgress(0, targetItem);
}
}

@xiaoshuimao
Copy link

me too. when will it be fixed?

@modao
Copy link

modao commented Nov 23, 2017

I meet the same problem,hope this will be fixed soon~

@Hfimy
Copy link

Hfimy commented Dec 15, 2017

Now i meet the same problem when beforeUpload return false ,the fileList turns into a wrong fileList that contain only type errors , my solution is to add a flag in the wrong file , and when return false ,do not change the fileList in handleChange

beforeUpload = (file) => {
    if (!/jpe?g|png$/.test(file.type)) {
        // message.error('Picture format error');
        file.flag=true;
        return false;
    }
    const isLt2M = file.size / 1024 / 1024 < 2;
    if (!isLt2M) {
        // message.error('Picture size more than limit(2M)');
        file.flag=true;
        return false;
    }
    return true;
}

handleChange = ({ fileList, file }) => {
     if (file.flag) {
         return;
      }
      this.setState({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.
Projects
None yet
Development

No branches or pull requests

5 participants