node.js - 如何获取要从文件池中删除的图像名称反应
问题描述
我正在使用React Filepond将图像上传到使用 Multer 的 node.js 服务器。上传工作正常,但是当我尝试在上传后立即撤消(删除)上传时,我收到 404 错误。
<FilePond
ref={ref => (this.pond = ref)}
files={this.state.files}
allowMultiple={false}
maxFiles={1}
name="photo"
server={{ url: "http://localhost:8000/api/uploads/", revert: "http://localhost:8000/api/revert/" }}
oninit={() => this.handleInit()}
onupdatefiles={fileItems => {
// Set currently active file objects to this.state
this.setState({
files: fileItems.map(fileItem => fileItem.file)
});
}}
/>
这可能是因为它找不到文件名。在节点方面,我将文件名设置如下:
const multerStorage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "public/img");
},
filename: (req, file, cb) => {
const ext = file.mimetype.split("/")[1];
cb(null, `hero-${Date.now()}.${ext}`);
}
});
这给了我:
英雄1564944240035
现在,当我尝试删除它时,我得到了 404。如果我再次尝试创建该名称,时间戳将会不同。获得该确切文件名以使删除工作的最佳方法是什么?
解决方案
推荐阅读
- ms-access - MS Access VBA Me.Recordset.Findfirst 运行时错误
- java - 如何为字符串java制作特定的if
- javascript - 保持不可变 JS 映射的顺序
- dataset - 如何从保持相同类别平衡的数据集中抽取样本?
- c - c客户端发送char但服务器正在接收数字
- go - 如何覆盖 func (l *Logger) Println(v ...interface{}) 方法 golang?
- android - Android 按钮之间的垂直空间
- java - 谷歌云 Sql/GAE 延迟
- java - 不推荐使用 IOUtils.toByteArray - 我们可以使用什么来代替?
- python-3.x - 在点处拆分 PySpark 数据框列