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

218
Views
Unable to receive files in request using express-fileupload

I use a REST client to test my app (Insomnia and postman). My app literally does nothing:

const express = require('express');
const app = express();
const fileUpload = require('express-fileupload');
app.use(express.json())
app.use(fileUpload());
app.post('/', fileUpload(), function(req, res) {
    console.log(req.files)
    res.send('a')
});
const PORT =  9999;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});

Whenever I try to upload a file to this service req.files is undefined. I took this code from express docs page and from a few stackoverflow questions and it just doesn't work for me. Content-length is good (40k seems right)enter image description here

Content-type is auto set by my REST client. Do I have to change this? I tried simply printing whole request object and body is empty and files is not even present there

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Just do one thing: remove file fileUpload() from post endpoint and check, find below code for your reference.

app.post('/', function(req, res) {
    console.log(req.files)
    res.send('a')
});
over 4 years ago · Santiago Trujillo Report

0

So for anyone wondering. fileupload requires form-data Content-type. Moreover, it also requires a file to have a "key" within this form-data. It's a shame documentation fails to mention this.

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