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

196
Vistas
how to get the value in then catch
           let newProduct = new ProductModel();


            for (let i in req.files) {

                if (req.files[i][0].fieldname == 'image1') {

                    cloudinary.uploader.upload(req.files.image1[0].path, { folder: fd, public_id: 'p1' })
                        .then(pic1 => {
                            newProduct.photo.push(pic1.url);
                            newProduct.updateOne({photo: newProduct.photo})
                                .then(() => res.redirect('back'))
                                .catch(err => console.log(err))

                        })
                        .catch(err => console.log(err))
                }
                else if (req.files[i][0].fieldname == 'image2') {
                    cloudinary.uploader.upload(req.files.image2[0].path, { folder: fd, public_id: 'p2' })
                        .then(pic2 => {
                            newProduct.photo.push(pic2.url);
                        })
                        .catch(err => console.log(err))
                }
                
            }

I have the ProductModel that have photo array attribute. I want to add pic.url from cloudinary. But outside the for loop, the newProduct.photo = []. How can I save the value outside the then ?

about 4 years ago · Santiago Trujillo
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