如何修复Node.js中的'TypeError:无法读取未定义的属性'path''(Multer) [英] How to fix 'TypeError: Cannot read property 'path' of undefined' in Nodejs(Multer)
本文介绍了如何修复Node.js中的'TypeError:无法读取未定义的属性'path''(Multer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试上传文件,但存在'TypeError:无法读取未定义的属性'path'.有什么办法解决这个问题?
I am trying to upload the file but there is 'TypeError: Cannot read property 'path' of undefined'. Is there any way to solve this?
exports.postimport = function (req,res) {
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'uploads');
},
filename: function(req, file, cb) {
cb(null, file.originalname);
}
});
var upload = multer({
storage: storage,
}).single('sheet');
upload(req, res, function(err) {
if (err) {
res.send(err)
} else {
console.log(req.file.path);
}
});
}
推荐答案
获取未定义路径的原因可能是目标目录(即上载文件夹的路径)不正确.
The reason you might be getting path of undefined may be that your destination directory (i.e path to your uploads folder) is not correct.
这篇关于如何修复Node.js中的'TypeError:无法读取未定义的属性'path''(Multer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文