Search code examples
node.jsexpresscloudinary

Get image paths uploaded to Cloudinary from NodeJS


I can correctly upload images to Cloudinary by looping through an array as follows:

        const imagesToCloudinary = req.files.map ( data => {
            cloudinary.v2.uploader.upload(data.path)
        });

        let imageResponses = await Promise.all(imagesToCloudinary);

        console.log(imageResponses);

But in console I never get any information which in this case I require the routes.

response in console:

[ undefined, undefined, undefined ]


Solution

  • const imagesToCloudinary = req.files.map ( data => {
       // missing return statement
        return cloudinary.v2.uploader.upload(data.path)
    });
    
    let imageResponses = await Promise.all(imagesToCloudinary);
    
    console.log(imageResponses);