Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda