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

375
Views
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 answers
Answer question

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 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!