Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda