Adding metadata to your images in Cloudinary enhances organization, searchability, and context. You can assign custom metadata through the Cloudinary Media Library or programmatically via the API.
- Using the Media Library
• Navigate to your Media Library.
• Click on the desired image to open its details page on the right-hand.
• Choose the Metadata tab and make the desired changes, click ‘Save’ to apply them.
Screenshot:
- Using the API
You can add metadata during the upload process or to existing images using Cloudinary’s API.
• During Upload:
Incorporate the context parameter to set metadata. Here’s an example in PHP:
$context = array("caption" => "Sample caption", "alt" => "Sample alternative text");
$result = \Cloudinary\Uploader::upload("my_image.jpg", array("context" => $context));
The context parameter isn’t limited to ‘alt’ and ‘caption’; you can add any custom key-value pairs:
$context = array("custom_field1" => "Value 1", "custom_field2" => "Value 2");
$result = \Cloudinary\Uploader::upload("my_image.jpg", array("context" => $context));
• For Existing Images:
To update metadata for images that are already uploaded:
$api = new \Cloudinary\Api();
$context = array("caption" => "Updated caption", "alt" => "Updated alternative text");
$api->update("my_image", array("context" => $context));
Note:
• Currently, only the ‘alt’ and ‘caption’ attributes are displayed in the Media Library UI. Other custom metadata fields can be accessed via the API.
• Ensure that your Cloudinary account is properly configured to handle metadata and that you have the necessary permissions to edit and update metadata fields.
For more detailed information, refer to Cloudinary’s official documentation on Contextual Metadata.
Comments
17 comments
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.
UPDATE
Now custom metadata values can be displayed, added and removed via the interactive Media library too.
Hi Can you please help how do I update caption for already uploaded images in JAVA?
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:
THEN SIMPLY DO SOMETHING LIKE THIS:
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?
@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
Raphi is correct :)
Java code example for future reference -
More details on our browsing capabilities -
http://cloudinary.com/documentation/admin_api#browse_resources
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?
Hi paul,
While the Admin-API is indeed rate limited, the same task can be achieved using the unlimited explicit() api.
Hi,
I'm using .NET integration in Xamarin.Forms with .NET Standard 2.0.
I use cloudinary.UpdateResource to update context for meta data,
but it will replace all exist meta data.
Has any function can I use to add/update/delete a meta data by meta data key/pair?
Hi,
Yes, you are correct. Currently, updateResource replaces the existing context with new ones.
I have passed this request to our product team.
You can use our list api to get the current context and then update it by appending existing with the new ones.
Hi,
Thank you for replay.
Other question:
I use cloudinary.Upload new image and assign exist PublicID to replace image,
but it will clear all exist meta data...
Has any function can I use to replace image without touch exist meta data?
Hi,
Upload image uploads a new image, it does not update an existing one.
If you want to update the image without changing the context, you can use the update api which will update your resource without changing the context unless you specifically specify the context for updating.
Hi,
Sorry for ask old question.
In .NET integration what api can use to update the image without changing the context?
Have some sample code?
Thank you.
Hi,
Currently, we don't have a way to update the resource without changing the context.
You can use the Admin API to list your resources(save the current context) and then update the resource(with the previously saved context)
Here's our .NET code for a reference.
https://github.com/cloudinary/CloudinaryDotNet/blob/e33d2a6b8fd2980cdd65a7c8b6292f0fdb4910de/Cloudinary/Cloudinary.cs#L388
Hi,
I'm trying to update caption for an existing photo, but I receive the message: 'Resource not found".
Here is a code sample to add a caption to your already uploded image:
cloudinary.v2.api.update("sample",
{ type: "upload", context: {caption: "test2"} },
function(error, result) {console.log(result); } );
Please sign in to leave a comment.