【问题标题】:Ant Design upload component - enable sending multiple files in single requestAnt Design 上传组件 - 允许在单个请求中发送多个文件
【发布时间】:2021-12-08 04:06:51
【问题描述】:

我正在使用ant design上传组件上传多个文件到服务器。

const props = {
    multiple: true,
    showUploadList: false,
    beforeUpload: () => {
        return false              
    },
    onChange: (info: any) => {
        console.log(info)
        setAttachmentLoader(true)
        info.fileList.forEach((file: any) => {
            formData.append("upload2[]", file.originFileObj)
        })
        formData.append("_charset_", "UTF-8")
        formData.append("upload2-data", "")
        uploadApiFunction(formData, (res: any) => {
            setAttachmentLoader(false)
            res.text && message.success(res?.text, 4)
        }, (err: any) => { console.log(err); setAttachmentLoader(false) })
    },
};

            <Upload {...props} fileList={[]}>
                <PrimaryButton text="Add attachment" />
            </Upload>

当我上传多个文件时,每个文件都会调用 api。我希望所有选定的文件都应在一个请求中上传到服务器。

谁能帮帮我?

【问题讨论】:

    标签: javascript reactjs file-upload antd


    【解决方案1】:

    每次文件列表发生变化时都会调用onChange,你需要将onChange调用转移到另一个按钮,如documentation所示

    【讨论】:

      猜你喜欢
      • 2015-03-17
      • 1970-01-01
      • 2020-03-22
      • 2013-03-30
      • 1970-01-01
      • 2018-07-19
      • 2018-12-30
      • 2013-02-02
      • 1970-01-01
      相关资源
      最近更新 更多