Skip to main content

Retrieve metadata via curl



  • Stephen Doyle
    Hi Pierrick,
    When using a simple <img> tag like your example, you'll receive the image but not the metadata.
    If there's image metadata you want to use in the alt parameter or as an image caption, you'll need to already have that available in your code at the time that you create the image tag. There are a few ways to store or obtain the metadata, depending on your requirements.
    For new images, we recommend storing the metadata at upload time. When uploading images to Cloudinary, the upload response includes the image metadata, so you could store it on your side at that time. 
    You can set custom key-value pairs using the context parameter at upload time, and these will be returned back in the upload response along with the public id and other info about the upload.
    For existing images, you can also use the Admin API to fetch the full details of an image, all images in a given folder, or all images with a given tag. If you specify `context=true` in that call you'll also get the context along with the other metadata and can use this to populate the image tags, or update your own database for future reference.
    Note that the Admin API has a rate limit, so you may need to fetch and store the metadata ahead of time to make sure it's always available before you need to use it in an image tag.
    If you're not currently storing the image metadata and need access to it from the client side, another option is to use the 'list' response type which will return a JSON list of images matching a given tag, including the `context` parameter if it's set. This can be called from client-side code there's documentation here for this method:
    If you have any further questions please let me know
  • Pierrick Boutruche

    Hi Stephen,

    Thanks for you reply.

    I was indeed thinking of a way to only have a single id stored in my backend and let Cloudinary handle metadata.

    This way I could avoid my actual architecture (that I don't really like), where I have a "pictures" table with cloudi_id + metadata and where I must add a join to this table everytime I need to get a picture's url... 

    It becomes complicated when I want to fetch several images from different tables or when I want to fetch more than one line (with associated picture) from a single table.

    Anyway, it seems that the best way for me would be to use the "list" API, right? Is it rate limited? Will it count in my cloudi usage plan if I use it?


  • Stephen Doyle

    Hi Pierrick,

    Retrieving a 'list' should be treated the same as any other resource (e.g. loading an image via its URL), and not subject to the rate limits of the Admin API.

    My only hesitation with recommending this method is that you'll need to make a call to Cloudinary to fetch the JSON metadata for all images with a given tag (which depending on your tags is potentially more images than just those you're about to display) before you have the information you need to create the image tag.

    This means the time before you can render your HTML is delayed while you make the HTTP request to fetch and parse the image metadata.

    Overall, I'd recommend the use of the 'list' resource type but with caching the image metadata in your own database so you don't need to another request each time you want to show that image, but if your requirements rule that out, you should be able to use just the 'list' option directly.



  • Pierrick Boutruche

    Yes I get it...

    Last question: would Cloudinary SDK (yours or thrid-party) do such things? Or do you have any idea? 

    I'm developping on React, and I saw that react-cloudinary did things like generating the <img> tag for you based on your screen width and things like that.

    I will dig in that direction, but if you know anything about it, let me know.


    Anyway, thanks for the help!


  • Stephen Doyle

    As you've noted, some of our SDKs use client-side information when creating the image tags, but other than that, you'll still need to fetch the image information either from Cloudinary or your own database.

    I don't think it would be too difficult to write a function that fetches the metadata and then uses it in an image tag, but how that function works would be specific to how your images are tagged in Cloudinary, in particular, so that you don't need to fetch and sort through the information for many more images than those you actually want to use.


Post is closed for comments.