“Télécharger plusieurs images Cloudinary” Réponses codées

Télécharger plusieurs images Cloudinary

    const cloudinaryImageUploadMethod = async file => {
      return new Promise(resolve => {
          cloudinary.uploader.upload( file , (err, res) => {
            if (err) return res.status(500).send("upload image error")
              console.log( res.secure_url )
              resolve({
                res: res.secure_url
              }) 
            }
          ) 
      })
    }
    
    router.post("/", [auth_middleware, upload.array("img", 3 )], async (req, res) => {

        const urls = [];
        const files = req.files;
        for (const file of files) {
          const { path } = file;
          const newPath = await cloudinaryImageUploadMethod(path)
          urls.push(newPath)
        }
        
        const product = new Product({
          u_id: req.user._id,  
          name: req.body.name,
          description: req.body.description,
          productImages: urls.map( url => url.res ),
        });

     }
Restu Wahyu Saputra

Plusieurs images sur le cloudinar

const cloudinaryImageUploadMethod = async file => {
      return new Promise(resolve => {
          cloudinary.uploader.upload( file , (err, res) => {
            if (err) return res.status(500).send("upload image error")
              resolve({
                res: res.secure_url
              }) 
            }
          ) 
      })
    }
    
    router.post("/", upload.array("img", 3 ), async (req, res) => {

        const urls = [];
        const files = req.files;
        for (const file of files) {
          const { path } = file;
          const newPath = await cloudinaryImageUploadMethod(path);
          urls.push(newPath);
        }
        
        const product = new Product({ 
          name: req.body.name,
          productImages: urls.map( url => url.res ),
        });

     }
Hurt Horse

Réponses similaires à “Télécharger plusieurs images Cloudinary”

Questions similaires à “Télécharger plusieurs images Cloudinary”

Plus de réponses similaires à “Télécharger plusieurs images Cloudinary” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code