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

206
Views
Multer req.file is undefined and directory created but image not there

I simply have this on my server

const storage = multer.diskStorage({
  destination: "public/something/images",
  filename: function (req, file, cb) {
    console.log(file, "file?");
    cb(
      null,
      file.fieldname + "-" + Date.now() + path.extname(file.originalname)
    );
  },
});

var upload = multer({ storage: storage });

app.post("/upload", upload.single("file"), (req, res) => {
  console.log(req.file, "req?"); // this is undefined?
  console.log(req.files.File, "req?"); // this is the correct file. why does the line above not work?
  res.json({ file: req.file });
});

on my frontend I have:

<input type="file" name="file" onChange={changeHandler} />

public/something/images does get created but the image is not inside it, why is this happening?

request:

  const endpoint = () => {
    const formData = new FormData();

    formData.append("File", selectedFile);

    fetch("http://localhost:4000/upload", {
      method: "POST",
      body: formData,
    })
      .then((r) => r.json())
      .then((a) => console.log(a));
  };
about 4 years ago · Juan Pablo Isaza
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!