TypeError:无法读取属性';mv';Node.js中未定义的

TypeError:无法读取属性';mv';Node.js中未定义的,node.js,Node.js,My Node.js代码: app.use(fileUpload()); app.post('/upload', function(req, res) { if (!req.files) return res.status(400).send('No files were uploaded.'); // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file

My Node.js代码:

app.use(fileUpload());

app.post('/upload', function(req, res) {
  if (!req.files)
    return res.status(400).send('No files were uploaded.');

  // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
  console.log(req.files);
  let sampleFile = req.files[0];

  // Use the mv() method to place the file somewhere on your server
  sampleFile.mv('C:/Users/MNaaraayanan/Downloads/boilerplate_new/src/main/ngapp/', function(err) {
    if (err)
      return res.status(500).send(err);

    res.send('File uploaded!');
  });
});
console.log()

{“上传[]”:
{name:'blank_user.png',
数据:,
编码:“7bit”,
错:,
mimetype:'image/png',
md5:'0c803e9cef05aedeada6fb9587f1b073',
mv:[函数:mv]}
TypeError:无法读取未定义的属性“mv” 在C:\Users\mnaarayanan\Downloads\样板文件\u new\src\main\ngapp\server.js:19:14 在Layer.handle[作为handle\u请求](C:\Users\MNaaraayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\Layer.js:95:5) 接下来(C:\Users\MNaaraayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\route.js:137:13) 在Route.dispatch(C:\Users\MNaaraayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\Route.js:112:3) 在Layer.handle[作为handle\u请求](C:\Users\MNaaraayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\Layer.js:95:5) 在C:\Users\mnaarayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\index.js:281:22 在Function.process_参数处(C:\Users\mnaarayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\index.js:335:12) 在Busboy.next(C:\Users\MNaaraayanan\Downloads\样板文件\u new\src\main\ngapp\node\u modules\express\lib\router\index.js:275:10) 在emitNone(events.js:111:20) 在Busboy.emit(events.js:208:7)


req.file
包含图像,但当我读取
.mv()
函数时,它会在您的console.log之后显示
未定义的

,我认为结构应该是

let sampleFile = req.files['uploads[]'];
sampleFile.mv();
它看起来像是
req.files={'uploads[]':{mv}
,而不是
req.files=[{mv}]

let sampleFile = req.files['uploads[]'];
sampleFile.mv();