Skip to main content

get url for the latest version of image

Comments

5 comments

  • Aleksandar Kostadinov

    Hi Jan,

    When overwriting or deleting resources via the Media Library or performing actions via the API such as upload + invalidate or destroy calls and supplying the 'invalidate' flag set to 'true', Cloudinary sends a request for invalidation at the CDN. By default, this invalidation was based on the URL and the URL convention that would be sent to the CDN depends on the account configuration and whether that is set to invalidate URLs using the full version component (e.g. v123456789), 'v1' for assets in folders or no version at all. These three URL conventions are detailed in the following support article: https://support.cloudinary.com/hc/en-us/articles/360001208732-What-URL-conventions-are-invalidated

    May I please ask you to share your cloud name and I will take a look at what configuration your account is in which would determine which URL gets sent for invalidation?

    To answer your question; The version number is returned in the upload response, however, it isn't possible to add a parameter like in your example (latestVersion) when generating the URLs as the SDK does not make a request (it just builds the URLs locally) so it wouldn't know what the latest version of any image is. Having said that, you will not need to record the version on your side and use that. Instead, once you re-upload and image and pass the invalidate flag the old URL would be invalidated, but it's a question of how your account is configured, because if the URL we are sending for invalidation does not match the one you are using then that would explain why you are seeing a cached image. Once this is corrected to reflect your setup the invalidation would take care of the cache and you won't need to worry about the versions.

    Best regards,

    Aleksandar

    0
  • oodoow

    Hello,

    cloudname is hvraiuw8x, I think I tried both settings, now I have Invalidate versioned URLs: "disabled". Will the invalidation be instant or is there still up one hour waiting time? 

    Also I have found in your API that I can get json with all images with some tag. In the JSON there is version and public_id, so in the worst case, I can get this JSON and search in it for the image with specified public_id and biggest version, is that right? This would mean, that I would need to upload every image with the same tag. Would be better, if I can get JSON with all images with some public_id.

     

     

    0
  • Aleksandar Kostadinov

    Hi,

    Firstly regarding your questions; Invalidation takes a matter of seconds, we just take a more conservative approach and that is why it mentions up to an hour.

    You can indeed get a list of images given a particular tag, however, as invalidation is made specifically for this, to also cover re-uploading and overwriting, using tags to get a list of the images just for the version numbers is unnecessary would not be needed in your case.

    Your cloud hvraiuw8x is currently configured to invalidate the default URLs (option 1 from the list above). This means the URLs that were sent for invalidation were without a version number for images in the root and a 'v1' for images in folders. Other URL formats that were used were not sent for invalidation.

    We've recently introduced a new invalidation option that is based on keys rather than the previous default URL based. The key-based invalidation is more flexible than the URL based one as it allows you to use any URL convention above and the resources would be invalidated correctly, thus not requiring you to make any changes to your system to change the URL convention you're currently using or if you're using more than one convention at the same time.

    What I've done now is configured your cloud to invalidate resources at the CDN using keys rather than based on the URL with a dedicated convention. I have also cleared any existing CDN cache so that if there were any images updated in Cloudinary that existing URLs referenced using other URL formats those are invalidated too. This new invalidation setting would apply to all invalidation requests going forward so please keep an eye the next time you are overwriting or deleting a resource and let us know how it goes.

    0
  • oodoow

    Hello,

    now it is very fast, image is invalidated in a matter of seconds. Thank you very much for your cooperation.

    Jan

    0
  • Aleksandar Kostadinov

    You're welcome Jan, glad I was able to help with that.

    0

Post is closed for comments.