“Carregue várias imagens Cloudinary” Respostas de código

Carregue várias imagens 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

Várias imagens no 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")
              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

Respostas semelhantes a “Carregue várias imagens Cloudinary”

Perguntas semelhantes a “Carregue várias imagens Cloudinary”

Mais respostas relacionadas para “Carregue várias imagens Cloudinary” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código