Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda