Home  >  Q&A  >  body text

javascript - Upload component selects a file and does not upload it immediately

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中文网2710 days ago595

reply all(4)I'll reply

  • 过去多啦不再A梦

    过去多啦不再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,
        });

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-19 10:15:15

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:15:15

    Has the question been solved?

    reply
    0
  • 高洛峰

    高洛峰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?

    reply
    0
  • Cancelreply