【问题标题】:FilePond revert uploads: the DELETE request does not contain unique ID. What to do?FilePond 还原上传:DELETE 请求不包含唯一 ID。该怎么办?
【发布时间】:2022-06-14 01:50:02
【问题描述】:

我是一个初学者,我为这个问题苦苦挣扎了好几天

我的问题是当我按下十字按钮来恢复我刚刚上传的文件时,它会向后端发送一个 DELETE 请求(我使用的是 Express)。但是,req.body 为空,后端无法识别用户想要还原的文件。

根据doc,它说包含一个唯一ID,但我找不到它。我想知道我是否需要在属性中手动添加一些东西,但我不知道要添加什么。下面是我的 ReactJs 代码。

<FilePond
                                    files={files}
                                    onupdatefiles={setFiles}
                                    allowMultiple={true}
                                    maxFiles={10}
                                    name="image"
                                    instantUpload={true}
                                    allowReorder={true}
                                    labelIdle='Drag & Drop your files or <span class="filepond--label-action">Browse</span>'
                                    itemInsertLocation='after'
                    

                                    // onprocessfiles={console.log('all files are uploaded!')}
                                    server={{url: "http://localhost:8080/adoptions",

                                            revert:{url:'/revert'}, 

                                             process:{
                                             url:'/process',
                                             method: 'POST',
                                             withCredentials: false,
                                             headers: {},
                                             timeout: 7000,
                                             onload: (res)=>{
                                                res = JSON.parse(res)
                                                console.log('RES:',res)
                                                console.log('res.filename:', res['msg'])
                                                pushToArrayAndLog(uniqueFileId,res.filename)
                                            },
                                            // onload: (response)=>response.key
                                            ondata: (formData) => {
                                                // getFileEncodeDataURL()
                                                // console.log(formData.values())
                                            // formData.append('extraField', this.id)
                                            return formData;
                                            }
                                             }}}

                                                />

【问题讨论】:

    标签: reactjs express filepond


    【解决方案1】:

    DELETE 是一种方法,用于删除您指定的 URI 处的资源。

    例如,DELETE 上的 https://fileserver.example/file.zip 意味着应该删除 file.zip

    所以DELETE 的目标是url 本身。 DELETE 请求不应该有正文,并且在许多情况下客户端和服务器会丢弃正文。 Filepond 文档提到了这些请求的主体这一事实告诉我,要么文档不正确,要么他们构建的 API 不正确。

    【讨论】:

    • 哦,是的! DELETE 不应该有 req.body。所以我的另一个问题是如何将文件标识符附加到 URL?例如,当我单击十字按钮还原文件 XYZ 时,我不知道在哪里可以找到文件 ID。我所知道的是在 React State 值(这是一个文件数组)中,我可以找到搜索文件的 ID。
    • 我对 FindPond 的文档感到很困惑,我不知道是不是我没有扎实的编程知识基础的问题。
    • 在这种情况下,我认为 Filepond 坏了。
    • 你认为我应该转储图书馆吗?或者应该有一些方法可以解决?
    • @ufo 除非您有其他理由尝试使用其他东西,否则我的第一步通常是报告错误并让他们有机会解决问题。作为一名软件工程师,我希望有人能在继续之前尝试报告问题。
    【解决方案2】:

    您的服务器应在 process 端点中返回唯一 ID。

    我看到您已经实现了 onload 挂钩,该挂钩用于查明/选择响应中的唯一 ID。因此,让我们假设您在 onload 中的 JSON 响应在对象中有一个 fileId。您将在 onload 挂钩中返回该 ID。

    process: {
      // other props
      onload: (res) => {
        const data = JSON.parse(res);
        return res.fileId; // FilePond passes this id to your server when you use the revert call
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 2017-05-18
      • 2011-06-02
      • 2011-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多