“Beberapa gambar di Cloudinary” Kode Jawaban

Unggah beberapa gambar 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

Beberapa gambar di 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

Jawaban yang mirip dengan “Beberapa gambar di Cloudinary”

Pertanyaan yang mirip dengan “Beberapa gambar di Cloudinary”

Lebih banyak jawaban terkait untuk “Beberapa gambar di Cloudinary” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya