Can I add metadata to images?

You can indeed set custom values to the alt and caption of your images.
These values can be either assigned interactively via our Media library or by using our API.

Media library:
Click on an image to access its details page, then click on the 'Edit meta data' link at the upper part of the page:
Edit_Metadata.png

API:
For example, the following sets the metadata of an image while uploading it (in PHP):

$context = array("caption" => "some caption", "alt" => "alternative");
$result = Cloudinary\Uploader::upload("my_image.jpg", array("context" => $context));

The context is actually not limited to the alt and caption only. You can add any arbitrary attributes. Here's an example in PHP:

$context = array("custom_field1" => "Some data 1", "custom_field2" => "Some data 2");
$result = \Cloudinary\Uploader::upload("my_image.jpg", array("context" => $context));

Note that these values can be accessed via the API only. Currently only the alt and caption attributes are displayed in the media library UI.

The metadata values can be set to already uploaded images too. For example:

$api = new \Cloudinary\Api();
$context = array("caption" => "some caption", "alt" => "alternative"); $api->update("my_image", array("context" => $context));
Have more questions? Submit a request

Comments

  • Avatar
    Yves Jaques

    Dear Itay,

    Are there any plans to allow users to view context metadata from the media library UI? This is actually a crucial use case for us and as a brand new user of the Advanced plan I'm really disappointed it doesn't support this, it's such an obvious use case to be able to easily view the custom key value pairs you need for your organizational purposes.

  • Avatar
    Itay Taragano

    UPDATE

    Now custom metadata values can be displayed, added and removed via the interactive Media library too.

  • Avatar
    Bharat Nanwani

    Hi Can you please help how do I update caption for already uploaded images in JAVA?

  • Avatar
    Yves Jaques

    Hi Bharat, this is how I update metadata via a java rest service:

    First assuming you have already created a connection to your cloud account:

    private Map config = ObjectUtils.asMap(
            "cloud_name", "xxxxxxxx",
            "api_key", "xxxxxxxxxx",
            "api_secret", "xxxxxxxxxxxxxxxx");
    private Cloudinary cloudinary = new Cloudinary(config);
    private Api api = cloudinary.api();
    

    THEN SIMPLY DO SOMETHING LIKE THIS:

        ArrayList<String> params = new ArrayList<>();
    
        //tags should be comma-separated
        List tags = image.getTags();
        StringBuffer tagStr = new StringBuffer();
        for (int i = 0; i < tags.size(); i++) {
            tagStr.append(tags.get(i));
            if (i != tags.size() - 1) {
                tagStr.append(",");
            }
        }
        params.add("tags");
        params.add(tagStr.toString());
    
        //context should be pipe | separated
        Custom custom = image.getContext().getCustom();
    
        StringBuffer contextStr = new StringBuffer();
    
        contextStr.append("title=").append(custom.getTitle())
                .append("|caption=").append(custom.getCaption())
                .append("|location=").append(custom.getLocation())
                .append("|countryCode=").append(custom.getCountryCode())
                .append("|copyright=").append(custom.getCopyright())
                .append("|date=").append(custom.getDate())
                .append("|credit=").append(custom.getCredit())
                .append("|lat=").append(custom.getLat())
                .append("|lng=").append(custom.getLng())
                .append("|keywords=").append(custom.getKeywords())
                .append("|printQuality=").append(custom.getPrintQuality())
                .append("|theme=").append(custom.getTheme());
    
        params.add("context");
        params.add(contextStr.toString());
    
        try {
            return api.update(id, ObjectUtils.asMap(params.toArray()));
        } catch (Exception e) {
            logger.error(e.toString());
            return null;
        }
    }
    
  • Avatar
    Daniel Meusburger

    Dear Cloudinary team,

    I did not find information in your documentation on how to actually access/retrieve meta data which I defined via the Media Library UI (e.g. a text description of a image or alt text). How can I access that information in Android / Java?

  • Avatar
    Raphi Stein

    @Daniel

    Yes, I also had to tinker to figure it out.

    To get the metadata, simply add the property

    context: true

    to your request.

    i.e. in Postman, you would do

    https://api.cloudinary.com/v1_1//resources/image?context=true

  • Avatar
    Maor Gariv

    Raphi is correct :)

    Java code example for future reference -

    api.resources(ObjectUtils.asMap("context", "true"));

    More details on our browsing capabilities -
    http://cloudinary.com/documentation/admin_api#browse_resources

  • Avatar
    paul headington

    We are getting rate limit exceed when attempting to update ~2450 image in lots of 10 at a rate of 500 ms per update. Surely this is reasonable?

    If not please advise how we can achieve please?

  • Avatar
    Nadav Ofir

    Hi paul,
    While the Admin-API is indeed rate limited, the same task can be achieved using the unlimited explicit() api.

    Edited by Nadav Ofir
Powered by Zendesk