0
votes

when I delete the image from my graphql server and using uploader.upload.destroy(public_id), it deletes from media library of cloudinary (https://cloudinary.com/console/media_library/folders/%2F)

but image is still available If I access it via cloudinary endpoint (https://res.cloudinary.com/db9rcrnuw/image/upload/v1576054005/47122.png)

I want to destroy those endpoints as well when the image is deleted.

here, screen.basePath means public_Id of the image


      const screen = await ctx.prisma
        .deleteScreen({
          id: args.screenId
        })
        .$fragment(fragment);

      if (scrn.basePath.length === 5) {
        console.log(scrn.basePath.length);
        cloudinary.uploader.destroy(screen.basePath, function(error, result) {
          console.log(result, error);
        });
        return screen;
      }
1

1 Answers

0
votes

The short answer is that this is caused by a combination of not using the 'invalidate' parameter in your destroy API call and a difference between which URL format (i.e. with a version number (v123456789), 'v1' or no version number) the resource is accessed using versus what format your account is configured to send for invalidation.

The first thing to do is ensure that all destroy API calls include the 'invalidate' parameter set to 'true' if you'd like CDN invalidation.

Regarding the URL formats; The 'v1576054005' that is part of delivery URLs is a version number that is essentially the UNIX timestamp of the upload time of the asset. Its main purpose is to always return the latest image and avoid CDN caching (upload API responses return the URL with the latest upload version). A bit more information on this topic can be found in this article - https://support.cloudinary.com/hc/en-us/articles/202520912-What-are-image-versions.

Please note that there are three possible URL formats Cloudinary can send for invalidation at the CDN, and these are outlined here: https://support.cloudinary.com/hc/en-us/articles/360001208732-What-URL-conventions-are-invalidated

Invalidation requests are sent when you delete or overwrite an image using the Media Library UI, or when you use the SDK/API, and also provide the 'invalidate' parameter, set to 'true'.

By default, all accounts send invalidations for the default format of URL which the SDKs produces, which uses no version number for assets in the root of your account, and a 'v1' placeholder for assets in folders (option 1 from the URL above).

If you were accessing the image with the full version component then that isn't sent for invalidation by default and why you are likely getting a cached copy returned.

In your case, the URL that would've been sent for invalidation would be without a version component (as the resource is in the root folder) i.e. https://res.cloudinary.com/db9rcrnuw/image/upload/47122.png

Depending on how you are building your URLs, i.e., if you're using the SDK helper methods, taking the URL from the url or secure_url fields of the Upload API response (which use the full version number), will determine the format and thus how your account should be configured to invalidate.

I suggest you to email Cloudinary support ([email protected]) and share a link to this thread as well as some details on how the URLs you're using are generated so that your account can be configured accordingly.