Search code examples
javascriptreactjsantd

Clear previous files when uploading new files antd upload


I'm using antd <Upload /> component so upload multiple files but the current behaviour is if the user uploads 2 files for the first time and again he uploads 1 more file again so the antd Upload onchange event return 3 files but I only want the file that has been uploaded recently, so any solution for it?

<Upload
    onChange={_.debounce(onUploadFiles, 100)}
    showUploadList={false}
    multiple
>
    <Button type="default" shape="round" className="main-upload-btn">
        <PlusOutlined /> Add Documents
    </Button>
</Upload>

Solution

  • I solved it by passing fileList prop as empty so it will always return newly uploaded files.

    <Upload
        onChange={_.debounce(onUploadFiles, 100)}
        showUploadList={false}
        fileList={[]}
        multiple
    >
        <Button type="default" shape="round" className="main-upload-btn">
            <PlusOutlined /> Add Documents
        </Button>
    </Upload>