javascript - Express 4 use multer as middleware got error -
var express = require('express'); var router = express.router(), multer = require('multer'); var uploading = multer({ dest: __dirname + '../public/uploads/', }) router.post('/upload', uploading, function(req, res) { console.log('uploaded'); })
i got error route.post() requires callback functions
error following photo upload tutorial here. maybe it's cause newer version of expresss? remember above way how put middle in route, why here doesn't work?
basing on multer docs, seems have use uploading.single()
or uploading.array()
middleware. example obtained example usage in multer docs:
var upload = multer({ dest: 'uploads/' }) app.post('/profile', upload.single('avatar'), function (req, res, next) { // req.file `avatar` file // req.body hold text fields, if there })
Comments
Post a Comment