'How do i upload either image or video to cloudinary using nodejs?

I want users to upload either image or video to cloudinary via nodejs and save the public id and url to mongodb, I'm using the if condition, but it is not working, Please help me out



Solution 1:[1]

We can post either image or video to the cloudinary via nodejs by specifying the resource_type:"auto"

Solution 2:[2]

//for video
const result = await cloudinary.uploader.upload(req.file.path, {
      resource_type: "video",
      folder: "video",
    });
//for image
const result = await cloudinary.uploader.upload(req.file.path, {
     
      folder: "image",
    });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kiran s jakkannavar
Solution 2 dammika rajapaksha