Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 an error Route.post() requires callback functions error following a photo upload tutorial here. Maybe it's cause by the newer version of expresss? I remember above is the way how we put middle in a route, but why here it doesn't work?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Basing on the multer docs, it seems like you have to use uploading.single() or uploading.array() as your middleware. This example is obtained from the example usage in the multer docs:

var upload = multer({ dest: 'uploads/' })

app.post('/profile', upload.single('avatar'), function (req, res, next) {
    // req.file is the `avatar` file 
    // req.body will hold the text fields, if there were any 
}) 
about 4 years ago · Santiago Trujillo Report

0

var express = require('express');
var router = express.Router(), 
multer = require('multer');

var uploading = multer({
  dest: __dirname + '../public/uploads/',
})
var type = uploading.single('file');

router.post('/upload', type, function(req, res) {
    console.log('uploaded');
})
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!