I still don't know how to deal with it, but I did console log in post route method: // @route POST /upload // @desc Uploads file to DB
(我仍然不知道如何处理它,但是我在控制台上输入了post route方法:// @route POST / upload // @desc将文件上传到数据库)
router.post('/', upload.single('file'), auth, (req, res) => {
console.log(req.file);
const newFile = new File({
fileID: req.file.id,
src: 'api/files/image/' + req.file.filename,
altText: 'No image',
caption: req.body.caption
})
newFile.save()
});
and I get:
(我得到:)
undefined
[0] { fieldname: 'file',
[0] originalname: 'slide1.jpg',
[0] encoding: '7bit',
[0] mimetype: 'image/jpeg',
[0] id: 5de06f65ff1bdb5388f1a44c,
[0] filename: 'e872d1cafee8d191b256d27efc5ac94f.jpg',
[0] metadata: null,
[0] bucketName: 'files',
[0] chunkSize: 261120,
[0] size: 235600,
[0] md5: '06ef6fba95a331af99276199589d3ed4',
[0] uploadDate: 2019-11-29T01:07:50.105Z,
[0] contentType: 'image/jpeg' }
So it looks that I have to await for request, because
(因此,看来我必须等待请求,因为)
req.file
(请求文件)
isn't yet defined, so I get error and it stop and don't post this req.body.caption.
(尚未定义,因此出现错误,它停止并且不发布此req.body.caption。)
That is what I suspect.(这就是我所怀疑的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…