【发布时间】:2019-04-02 11:01:29
【问题描述】:
我正在构建一个应用程序,在该应用程序中填写一个也有文件的表单。我从“req.file”获取文件,从“req.body”获取其他内容。 “文件”不是“必需的”。用户可以附加或不能附加。当用户附加时,一切顺利,但是当用户不附加文件时,我发现了这个错误。 can not read property "buffer" of undefined.。我已将“图像”的猫鼬模式类型设置为“缓冲区”。这是我从“req”获取文件和其他数据时的代码。
image: req.file.buffer,
geolocation: req.body.geolocation,
details: req.body.details,
location: req.body.location,
status: req.body.status,
spam: req.body.spam,
【问题讨论】:
-
在将
req.file.buffer分配给图像之前检查req.file。
标签: node.js mongodb file mongoose buffer