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

364
Vistas
How to get file data and other form data sent in POST request in Node Js

I am sending form data values using Postman as given here. Postman Request. I am making use of NodeJS server in the backend to get the data from this POST request.

The code for my app.js file is given below.

require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();

app.use(bodyParser.json({
  limit: '50mb',
}));

app.use(bodyParser.urlencoded({
  limit: '50mb',
  extended: true
}));

const { multerUploadOneFile } = require(path.resolve(__dirname, 'helpers', 'multerConfig'));

app.post('/upload', function (req, res) {
  // **Here I need to get the other parameters in the request body, i.e ```userId```, ```fileType```  
  console.log(req.body);
  multerUploadOneFile(req, res, function (error) {
    if (error) {
      return res.status(401).send({
        status: 'failure',
        message: error.message
      });
    }
    return res.status(200).send({
      status: 'success',
      message: 'successfully uploaded file.',
    });
  })
});

I am logging the request body in /upload api endpoint but I am not able to get anything. Please let me know how can I get the req.body in callback of /upload api endpoint.

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

body-parser doesn't support multi-part bodies.

multer (which you're correctly using) does, however it needs to execute and parse the request before you'll be able to access anything.

multerUploadOneFile needs to execute before you have acceess to .body or .file.

app.post('/upload', function (req, res) {
  multerUploadOneFile(req, res, function (error) {
       console.log(req.body, req.file);
almost 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