This support forum is no longer in use. Please use the Cloudinary Community at https://community.cloudinary.com/ to receive assistance from other members of the community and from Cloudinary's support team. For account-specific questions or if you believe that you've encountered a bug, please contact the Cloudinary team directly via the "submit a request" option on this support site.

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

    -1
    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

Post is closed for comments.