【发布时间】:2018-09-29 15:50:32
【问题描述】:
我的 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():
{ 'uploads[]':
{ name: 'blank_user.png',
data: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 fb 00 00 00 fb 08 02 00 00 00 23 10 75 f1 00 00 00 19 74 45 58 74 53 6f 66 74 77 61 72 65 00 ... >,
encoding: '7bit',
truncated: false,
mimetype: 'image/png',
md5: '0c803e9cef05aedeada6fb9587f1b073',
mv: [Function: mv] } }
TypeError:无法读取未定义的属性“mv” 在 C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\server.js:19:14 在 Layer.handle [as handle_request] (C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\layer.js:95:5) 在下一个(C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\route.js:137:13) 在 Route.dispatch (C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\route.js:112:3) 在 Layer.handle [as handle_request] (C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\layer.js:95:5) 在 C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\index.js:281:22 在 Function.process_params (C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\index.js:335:12) 在 Busboy.next (C:\Users\MNaaraayanan\Downloads\boilerplate_new\src\main\ngapp\node_modules\express\lib\router\index.js:275:10) 在 emitNone (events.js:111:20) 在 Busboy.emit (events.js:208:7)
req.file 包含图像,但是当我阅读.mv() 函数时,它显示的是undefined。
【问题讨论】:
标签: node.js