javascript - Upload component selects a file and does not upload it immediately
PHP中文网
PHP中文网 2017-05-19 10:13:15
0
4
578

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?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(4)
过去多啦不再A梦
  • 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,
    });
Peter_Zhu

After you select the file, base64 will be displayed. Just save it together when you click Save

Ty80

Has the question been solved?

小葫芦

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?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!