着名的TypeError:无法读取属性未定义的属性“path”

我有一个问题将上传一个docx文件与Muller。

我所宣称的:

app.js multerconfiguration

var storage = multer.diskStorage({ destination: function(req, file, callback) { callback(null, __dirname + process.env.UPLOAD_DIR); // '/uploads' } }); var uploadService = multer({ storage: storage, // limits: { fileSize: maxSize }, fileFilter: function(req, file, callback) { var ext = path.extname(file.originalname) if (ext !== '.docx') { return callback(res.end('Only docx are allowed'), null) } callback(null, true) } }); app.post('/upload', uploadService.single('file'), uploadController.postFileUpload); 

upload.js

 exports.postFileUpload = (req, res, next) => { // Data receiver parameters var jsonData = ''; var buffer = generateDoc(jsonData, req.file); [...] res.status(200).end(); }; function generateDoc(data, file) { var doc = new Docxtemplater(); var wordDocument = file; var filepath = wordDocument.path; console.log(filepath); // prints file path ex : D:\doc_tpl\uploads\0816cdb5c82d458ed930d0048b603d8a var content = fs.readFileSync(path.resolve(filepath), 'binary'); // throws error, wtf ? [...] return buffer; } 

然后我有这个错误:

TypeError:无法在generateDoc(D:\ doc_tpl \ controllers \ upload.js:17:31)中读取未定义的属性'path'

我不能使用var,正如你所看到的,通过另一个variables不会解决问题..

我使用的是Node@8.7,“express”:“^ 4.15.4”,“multer”:“^ 1.3.0”。 而我的帕格html身体似乎干净:

 form#file-uploader.dropzone(method='post', action='/upload' enctype='multipart/form-data') .fallback input(name='file' type='file') 

这个代码有什么问题?

       

网上收集的解决方案 "着名的TypeError:无法读取属性未定义的属性“path”"