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

191
Views
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
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!