FilePond revert uploads: DELETE请求不包含唯一ID.该怎么办?



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

我的问题是当我按下交叉按钮恢复我刚刚上传的文件时,它向后端发送DELETE请求(我使用Express)。然而,要求。正文为空,后端无法识别用户想要还原的文件。

根据文档,它说包含一个唯一的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;
}
}}}
/>

服务器应该在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
}
}

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

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

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

最新更新