Nodejs: How can I check if public_id exists on Cloudinary?
Hello,
I am currently doing validations to check if public_id exists in Cloudinary. Is there a method that I am not seeing in the API documentation?
1
-
Gabriel - One technique is to try and get details for the specific asset by declaring its Public ID. If the asset doesn't exist in your system, it will return an error.
Here's a code sample, using Node.js, to try and retrieve a file with a Public ID of "kitten".
require('dotenv').config();
const cloudinary = require('cloudinary').v2;
cloudinary.api.resource('kitten')
.then(result => console.log(result))
.catch(error => console.error(error));I would try this and see if it works for you. More details about this Admin API method can be found here: https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource
Yours Truly,
-Sam
-1 -
Hi Sam,
Thank you very much for your quick reply. I will check this method right away.
0
Post is closed for comments.
Comments
2 comments