Nodejs: How can I check if public_id exists on Cloudinary?

Comments

2 comments

  • Avatar
    Sam Brace

    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

    0
    Comment actions Permalink
  • Avatar
    Gabriel Martinez

    Hi Sam,

    Thank you very much for your quick reply. I will check this method right away.

    0
    Comment actions Permalink

Please sign in to leave a comment.