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

310
Views
How to get info from an object with multer

I need to get the filename info from two files sended with multer, but when I try to send a JSON with the response, it sends a Object: null prototype and the info from the images. But I can´t access to it. What can I do? Here is my code:

// Multer File
const multer = require("multer");
const path = require("path");

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, path.join(__dirname, "../../imagesDirectory"));
  },
  filename: (req, file, cb) => {
    cb(
      null,
      `${req.params.campana}-${req.params.metodo}-${file.fieldname}-${new Date()
        .toISOString()
        .replace(/:/g, "-")}-${file.originalname}`
    );
  },
});

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

const uploads = upload.fields([
  { name: "image1" },
  { name: "image2" },
  { name: "image3" },
  { name: "image4" },
  { name: "image5" },
  { name: "image6" },
  { name: "image7" },
]);

module.exports = uploads;
// Controller
const uploadFile = async (req, res) => {
  if (!req.files) {
    console.log("You need to add an image");
    res.json({ err: "You need to add an image" });
  } else {
    console.log(req.files);

    let name = req.files.filename;
    res.json({ msg: "Image Upload", rows: name });
  }
};

module.exports = { uploadFile };
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!