How to check if an asset exists on my account?

Follow

Comments

6 comments

  • Avatar
    Itay Taragano

    Hi Alexandar,

    I'll be happy to assist with some clarifications.

    Could you give more details on how you are uploading the files to Cloudinary? Specifically, are you using the Upload method and are you using one of the SDKs? Once we have the information, we can guide you on the exact steps with examples that will work for you.

    Generally speaking, here are a few things that you can check:
    * Ensure that the resource will have an exact unique public ID, either by specifying one (by setting the `public_id` parameter as part of the upload params, or by setting `use_filename=true`, and `unique_filename=false`. This will ensure that the file name on Cloudinary is the same as the file name you are uploading. If not, we'll create a random name/append random characters to make the file unique.
    * While running the bulk upload script, set `overwrite=false`. This way, if the resource already exists, the file will not be re-uploaded.

    Regarding HEAD requests and whether they'd be counted as a transformation:

    • If the resource exists, then a HEAD request to that resource will not be counted as a transformation
    • If the resource doesn't exist and the request returns a 404, a transformation will not be charged.
    • If the resource didn't exist at first, and by the head request that resource "becomes" existent (e.g., in cases of fetch or auto-upload), then a transformation is counted exactly as any other first-time upload would. However all subsequent HEAD requests for that URL will not count as additional transformations.

    I hope this helps

    0
    Comment actions Permalink
  • Avatar
    Maor Gariv

    Hi,

    Thanks for reaching out.

    In case the resource has a backup, the deleted image (i.e., the placeholder) will indeed come up in the explicit call. I went ahead and opened a feature request to handle this situation (return a placeholder=>true to indicate a deleted resource).

    Please note that a HEAD request or using our Admin API's resource will give the correct result.

     

    Hope it helps!

    Best,

    Maor

    0
    Comment actions Permalink
  • Avatar
    funky_jnto

    An exception is not thrown by explicit() to a deleted image.

    How to determine deleted or not?

    0
    Comment actions Permalink
  • Avatar
    Jannik Mewes

    While this is looking like a good solution it is actually harmful in some situations. One must not do this check right before uploading as it CACHES A 404 ERROR. One has to either skip such a check or make sure to delay the next call to the resourse, else the exponential error cache will lead to unexpected errors.

    0
    Comment actions Permalink
  • Avatar
    Maor Gariv

    Hey all,

    Happy to update that we now return the placeholder parameter when executing Explicit on a resource (similar to the way we return it in the upload response), as requested in this thread:)

    Best regards,

    Maor

    0
    Comment actions Permalink
  • Avatar
    Alexander Seltenreich

    First of all: I am currently getting started with Cloudinary and everything seems very impressive so far.

    But all these ways seem unsatisfying to me. I want to batch-upload files to Cloudinary and check if they have already been uploaded before but #1 seems unreliable and seems to cause a transformation (I guess partly because the just uploaded file has not been retrieved at all yet - although I don't intend to retrieve any actual binary data), #2 is meant for something completely different and #3 counts against my rate limit.

    I didn't expect any hassle like this at all for such a basic action.

    0
    Comment actions Permalink

Please sign in to leave a comment.