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

198
Views
Multer req.file no está definido y el directorio se creó pero la imagen no está allí

Simplemente tengo esto en mi servidor.

 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 }); });

en mi frontend tengo:

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

public/something/images se crea pero la imagen no está dentro, ¿por qué sucede esto?

solicitud:

 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!