How to get private image using public id with Admin API?

Options
Kyriacos
Kyriacos Member Posts: 8

Hello,

I am using signed uploads, which means my backend generates parameters, including a public id, and a signed signature for the frontend to use to upload an image.

Some of the images that are uploaded have type = private. On my backend, I query Cloudinary for the images that the backend has generated a signature for using the get resource by public id Admin API However, I noticed that if an image is private, this endpoint returns a 404. On the other hand, if I query for the image using the get resource by asset id API, it works.

The problem is that I do not have the asset id on the backend at the moment I'm trying to query for the resource, since the backend has only generated a signature and has no knowledge of the upload progress made by the frontend. (I have webhook notifications setup - but for I'm implementing a mechanism to sync without webhooks.) Therefore, I can only query for the asset using the public id, but this does not seem to work.

Is there any way around this?

Answers

  • Zachary
    Zachary Member, Cloudinary Staff Posts: 35
    Options

    Hi there,

    If you are looking up a single resource by public id the default type will be upload, you'll need to update this for assets of type private.

    ```
    cloudinary.v2.api
    .resource('rwkaliebnufp3bxyrvyo',
    { type: 'private'})
    .then(result=>console.log(result));
    ```
    I hope this helps, please let us know if you still run into any issues and feel free to always open a ticket with support.

    https://support.cloudinary.com/hc/en-us/requests/new

    Read more via our documentation on the subject

  • Kyriacos
    Kyriacos Member Posts: 8
    edited June 27
    Options

    Hi Zachary,

    Your suggestion has been very helpful. Thank you very much!