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

128
Views
Empty req.files with connect-multiparty and body-parser

I'm trying to upload a file with connect-multiparty on my api but I can't make it works.

Here my code (a sample, because my api have a lot of working routes):

var express             = require('express');
var bodyParser          = require('body-parser');
var multipart           = require('connect-multiparty');
var app                 = express();
var multipartMiddleware = multipart({ uploadDir: './imagesPath' });

// Define middleware
app.use(bodyParser.urlencoded({ extended: true })); // Support encoded bodies
app.use(bodyParser.json());                         // Support json encoded bodies

var router = express.Router();                      // Get an instance of the express Router

router.post('/testFileUpload', multipartMiddleware, function(req, res) {
    console.log(req.body, req.files);

    // Some other code
});

When I try to upload a file both req.body and req.files are empty {}

I know Body-Parser doesn't support multipart/form-data anymore so I'm trying to find a way to use it with another package but with no success so far.

I've tried with busboy, connect-busboy, multer, formidable, express-formidable, express-fileupload but everytime req.files is undefined, so I kinda feel I've make some progress with connect-multiparty by having req.files empty.

I've seen some topics with similar problems like this one, this one or this one but unfortunatly none of those helped me.

In client side I'm using Advanced REST Client and Postman.

Any ideas what I'm doing wrong ?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

To whoever has this problem, I found removing the Content-Type headers on Postman with value "application/javascript" worked for me. I just hadn't noticed the whole time, while I tried different packages same as OP.

about 4 years ago · Santiago Trujillo Report

0

put enctype="multipart/form-data" in your tag form on html

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!