- <Upload
- customRequest={customRequest}
- accept=".csv"
- showUploadList={false}
- >
- <Button icon={<UploadOutlined />}>上传 CSV 文件Button>
- Upload>
accept 代表限制的上传类型 也可设置 .excel
- // 文件上传 ( CSV )
- const customRequest = async ({ file, onSuccess, onError }: any) => {
-
- // 检查文件扩展名是否为 .csv
- const isCSV = file.name.split('.')[1].toLowerCase();
- if (!isCSV) {
- message.error("アップロードできるのはCSVファイルだけです ");
- return;
- }
-
- // 执行文件上传逻辑
- const formData = new FormData();
- formData.append("file", file);
-
- for (const entry of formData.entries()) {
- console.log(entry[0], entry[1]);
- }
-
- const [_,res] = await to(uploadCvs(formData));
- if(JSON.parse(res).code === '102') {
- message.success(JSON.parse(res).message)
- }
- };
通过 new FormData() 转换成表单数据发送给后端
时小记,终有成。