储存源文件
const formData = new FormData();
formData.append('file', v);
// 添加其余参数
formData.append('source', graphActive);
//上传
const token = sessionStorage.getItem('token');
const headers = {
Authorization: token,
};
const handleUpload = {
name: 'file',
headers: headers,
// action: `${api}${uploadApi}`,
beforeUpload: (file) => {
const type = file.type.substring(file.type.lastIndexOf('.') + 1).toLowerCase();
const isExist = type === 'sheet';
if (!isExist) {
message.error(`只能上传excel类型`);
}
return isExist || Upload.LIST_IGNORE;
},
onChange(info) {
/* if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList);
} */
if (info.file.status === 'done') {
const v = info.file.originFileObj;
upload(v, info.file.name);
} else if (info.file.status === 'error') {
message.error(`${info.file.name} 导入失败`);
}
},
};
const upload = async (v, name) => {
console.log(v);
const formData = new FormData();
formData.append('file', v);
// 添加其余参数
formData.append('source', graphActive);
const data = await getUpload(formData);
if (data.code === '200') {
message.success(`${name}导入成功`);
handleGetList();
}
};
<Upload {...handleUpload} showUploadList={false} maxCount={1}>
<Button
icon={<Icon xlinkHref="#icon-Import_1_14" style={{ marginRight: '8px' }} />}
className={`${style.operateButton} `}
>
批量导入
</Button>
</Upload>
nigix不允许post上传静态资源报错405
Upload: customRequest 通过覆盖默认的上传行为,可以自定义自己的上传实现,
将状态改为成功
customRequest={(a, v) => {
a.onSuccess();
}}