Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda