Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload multiple 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 ),
        });

     }
Comment

multiple images on 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 ),
        });

     }
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongoose delete request 
Javascript :: unshift 
Javascript :: windows how to set process.env variables 
Javascript :: nodejs aws s3 stream upload 
Javascript :: fetch data from asyncstorage react native 
Javascript :: jquery select all checkboxes 
Javascript :: react check if mounted 
Javascript :: regex char and number 
Javascript :: onclick inline function react 
Javascript :: javascript absolute path 
Javascript :: teste 
Javascript :: get closest element id jquery 
Javascript :: Angular version chrome console 
Javascript :: expo react native 
Javascript :: javascript add class to element 
Javascript :: Nullish Coalescing Vs Logical OR opreators 
Javascript :: js random numbers 
Javascript :: react yup password with number string and uppercase 
Javascript :: read file size javascript 
Javascript :: find object in array by property javascript 
Javascript :: how to declare a variable inside a class in javascript 
Javascript :: angular http put 
Javascript :: javascript array to table 
Javascript :: how to change user password firebase 
Javascript :: js window location relative path 
Javascript :: convert utc string to date format of mm dd/mm/yyyy in javascript 
Javascript :: react scrollTop smooth 
Javascript :: promise states javascript 
Javascript :: jquery set input value 
Javascript :: javascript remove innerhtml 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =