Below is my utility function for destroying the cloudinary resources and the splitter URL which I have got from the DB but I am unable to delete the videos, only images get deleted even I have specified the resource type as well.
Function
const deletefromCloudinary = async (url) => {
try {
const splitURL = url.split("/");
console.log("Split URL:", splitURL);
// Extract the public ID with the correct filename format
let publicId = splitURL.slice(7).join("/");
// Remove extra Cloudinary-generated extensions (like `.webp`)
publicId = publicId.replace(/\.(jpg|jpeg|png|webp|gif|mp4|mov|avi|mkv)$/, "");
console.log("Corrected Public ID:", publicId, {resource_type: `${splitURL[4]}`});
// Use the correct delete method
const deleteResponse = await cloudinary.uploader.destroy(publicId);
console.log("Delete Response:", deleteResponse);
return deleteResponse;
} catch (error) {
throw new Apierror(404, `No resource found for ${url} to delete`);
}
};
Splitted URL
Split URL: [
'http:',
'',
'res.cloudinary.com',
'my-cloudinary',
'image',
'upload',
'v1738605970',
'youtube',
'youtube',
'1c3302f1145a4ca991633129c15264c7.png.webp'
]
The uploader
const response = await cloudinary.uploader.upload(localfilepath, {
resource_type: "auto",
use_filename: true,
public_id: `youtube/${filename}`,
folder: "youtube",
overwrite: true,
chunk_size: 6000000
})
I am unable to figure out why I cannot delete the video files