Delete Image from Cloudinary

Delete Image from Cloudinary

The deleteImagesFromCloudinary utility streamlines the process of deleting images from your Cloudinary by simply passing their public IDs.

Let's first dive into an example. Afterward, we'll delve deeper into the syntax and configuration options of the deleteImagesFromCloudinary utility:

// import express and anything else that you need
// import "deleteImagesFromCloudinary"  from 'express-cloudinary-image-handler'
 
const app = express()
 
app.get('/delete-images', async (req, res) => {
 
    try {
        const delete_report = await deleteImagesFromCloudinary({
            publicIds: ['product/w7xrxsqbu9ial4katnud', 'product/w7xrxsqbual4katnud']
        })
 
        if (delete_report.isError) {
            return res.json({
                status_code: delete_report.errorInfo.statusCode,
                message: delete_report.errorInfo.message
            })
        }
 
        return res.json({
            message: 'Deleted Images Successfully'
        })
    }
 
    catch (error) {
        return res.json({ message: "Something went wrong" });
    }
})
 

deleteImagesFromCloudinary - Parameters

Parameter NameTypeRequirementDescription
publicIdsarrayRequiredList of public IDs of the images to be deleted from Cloudinary.

deleteImagesFromCloudinary - Return Value

Field NameTypeDescription
isErrorbooleanIndicates if there was an error during the deletion.
errorInfoobjectContains error details if isError is true.

errorInfo Object Properties:

Property NameTypeDescription
statusCodenumberThe status code of the error.
messagestringThe error message.