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

161
Views
Upload an array of images to Cloudinary using Nodejs

I am creating a Real estate server and I have created a small form to test my endpoint. now I sending the images back to the server as an array after they have been encoded to base64. I am checking first if the req.body.image.isArray then proceeding to upload however I think I am getting it wrong in the function since it takes two arguments, the item uploaded and the upload preset. I am trying to send every image in the array by looping through but it seems I receive the 404 status. How do I loop through each image in this array and get back the uploadResponse for each image?

My Code.

Router.post("/createproduct", async (req, res) => {
  const { error } = productValidation.validate(req.body);
  if (error) {
    return res.status(400).json({ message: error.details[0].message });
  }
  try {
    if (req.body.image.isArray) {
      const uploadRes = await cloudinary.uploader.upload(
        req.body.image.array.forEach((img) => {
          return img;
        }),
        {
          upload_preset: "fanakaplatinums",
        }
      );
      if (uploadRes) {
        await productsModel.create({
          name: req.body.name,
          location: req.body.location,
          description: req.body.description,
          price: req.body.price,
          amenities: req.body.amenities,
          image: uploadRes,
        });
        return;
      }
    } else {
      res.status(400).json({ message: "an error occured" });
    }
    res
      .status(200)
      .json({ message: "the house was added to database successfully" });
  } catch (error) {
    res.status(500).json({ message: error});
  }
});

how the array I am sending back to the server looks like enter image description here

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!