I'm trying to do upload using node.js.
router.post('/image', [ multer(), function(req, res) {
var file = req.files.file;
console.log(file);
res.end();
}]);
What's wrong with above code? I'm getting error of
Error: Route.post() requires callback functions but got a [object Object]
at Route.(anonymous function) [as post]
Most likely you're following an older tutorial that uses multer
's older API. The API changed ~v1.0.0 and you can find an example of the new API here . For example:
var upload = multer();
router.post('/image', [ upload.any(), function(req, res) {
var file = req.files.file;
console.log(file);
res.end();
}]);
There is something wrong about router parameters & multer usage. You should see multer documentation
Here is an example to help you fit your code.
var multer = require('multer');
var upload = multer({ dest: 'uploads/' });
router.post('/image', upload.single("image"), function(req, res) {
var file = req.file;
console.log(file);
res.end();
}]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.