antd's Upload component, I want to not upload the file immediately after selecting it, but upload it together after I press the save button. How to do this?
認(rèn)證高級(jí)PHP講師
Use beforeUpload to store the things to be uploaded in the store (state can also be used), and finally return false to prevent uploading.
<Dragger
name="ver_file"
action="version_add"
showUploadList
disabled={activeRow.id !== 0}
fileList={fileList}
onRemove={() => {
// 清空文件列表
dispatch({
type: 'SystemSettings/Version/changeFileList',
payload: {
file: {},
fileList: [],
},
});
}}
beforeUpload={(curFile, curFileList) => {
// 將上傳的東西存到store里,返回false阻止上傳
dispatch({
type: 'SystemSettings/Version/changeFileList',
payload: {
file: curFile,
fileList: curFileList,
},
});
return false;
}}
>
When submitting, append file to FormData
const data = new FormData();
// 循環(huán)把字段全部加進(jìn)去
Object.entries(values).forEach((item) => {
data.append(item[0], item[1] || '');
});
data.append('ver_file', file);
dispatch({
type: 'SystemSettings/Version/submitData',
payload: data,
});
After you select the file, base64 will be displayed. Just save it together when you click Save
I have the same question, lz I want to share it. I also encountered a requirement that I don’t want to upload it immediately. How can I do it?