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

120
Views
Multer give undefined for req.file

I'm make api to upload files using node js.

i using multer for handle multipart/form-data but when i console.log(req.file) it appears undefined

Route

const uploadController = require('../controller/upload.server.controller');
const multer = require('multer');

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

/**
 * Routes
 */
module.exports = function (app) {
  app
    .route('/api/upload')
    .post(upload.single('image'), uploadController.upload);
};

Controller

exports.upload = async function (req, res) {
    console.log(req.file);
};

my request with postman

request with postman

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

// init
const multer = require('multer');
const path = require('path');

// "images" are the folder name
const fileStorage = multer.diskStorage({
   destination: (req, file, cb) => {
     cb(null, 'images');
   },
});
// put this to config the multer
app.use(multer({ storage: fileStorage }).single('image'));
// this is for serving file staticly with "path" module 
app.use('/images', express.static(path.join(__dirname, 'images')));

Also make sure you write enctype=multipart/form-data in the form tag not in the input tag AND add type=file attribute in the input tag

about 4 years ago · Juan Pablo Isaza Report

0

Try this:

app.post('/api/upload', upload.single('image'), function (req, res, next) {
  console.log(req.file);
})
about 4 years ago · Juan Pablo Isaza Report

0

Try using req.file as per the docs source: multer

about 4 years ago · Juan Pablo Isaza 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!