How to fix 'TypeError: Cannot read property 'path' of undefined' in Nodejs(Multer)

拟墨画扇 提交于 2019-12-20 06:23:46

问题


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);
       }
});
}

回答1:


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.



来源:https://stackoverflow.com/questions/55864278/how-to-fix-typeerror-cannot-read-property-path-of-undefined-in-nodejsmulte

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!