Reputation: 327
<Form.Item
name="upload"
label="Upload"
valuePropName="fileList"
getValueFromEvent={normFile}
multiple="false"
>
<Upload accept=".csv" name="logo" multiple="false" action="/upload.do" listType="picture">
<Button icon={<UploadOutlined />}>Click to upload</Button>
</Upload>
</Form.Item>
mutiple files are allowed as below
Upvotes: 3
Views: 5447
Reputation: 2042
I handle this problem by Css, Check my list array length, if true define a className to the upload button which prevent to click.
const [list, setList] = useState(null);
<Dragger //its one of antd upload components
{...settings}
className={list?.length ? 'blocked' : undefined}
>
.blocked {
pointer-events: none;
opacity: 0.5;
}
Upvotes: 0
Reputation: 620
The solution to your first question is very simple. The Ant Design Upload component API (now?) contains maxCount
, which limits/controls the number of uploaded files.
Set it to 1 and that will limit the amount of files uploaded to just 1. If a user picks up another file, it will replace the one selected before.
So, you should have something like this in the end:
<Form.Item
name="upload"
label="Upload"
valuePropName="fileList"
getValueFromEvent={normFile}
multiple="false">
<Upload
accept=".csv"
name="logo"
multiple="false"
action="/upload.do"
listType="picture"
maxCount={1} //this is what limits the number of files uploaded
>
<Button icon={<UploadOutlined />}>
Click to upload
</Button>
</Upload>
</Form.Item>
Upvotes: 4