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?
过去多啦不再A梦2017-05-19 10:15:15
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();
// 循环把字段全部加进去
Object.entries(values).forEach((item) => {
data.append(item[0], item[1] || '');
});
data.append('ver_file', file);
dispatch({
type: 'SystemSettings/Version/submitData',
payload: data,
});
天蓬老师2017-05-19 10:15:15
After you select the file, base64 will be displayed. Just save it together when you click Save
高洛峰2017-05-19 10:15:15
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?