How to retrieve metadata
I'm using java API to retrieve Images with a specific Tag.
I am editing some metadata ('alt') of the image from Cloudfoundry UI.
Along with the Resource I want this metadata do be part of the response
I'm trying with 'image_metadata' set to true but it does not seem to have any effect. The returned resource still do not have the 'alt' metadata I'm setting on the image via UI.
Do you know how can I retrieve the metadata associated to the image?
ApiResponse resources = cloudinary.api().resourcesByTag("myTag", ObjectUtils.asMap("image_metadata", true));
-
I answer myself. You should pass context=true to get the metadata info
ObjectUtils.asMap("context", "true")
1 -
Great:)
Feel free to reach out again with further questions or requests.
0 -
Hi Maor,
I need to do the same but i need to use javascript API. I have a tag on metadata but when i get the resource by tag using URL, I dont get metadata back.
Can you help?
https://api.cloudinary.com/v1_1/michaels-stores/resources/image/tags/09048D?context=true
Thanks,
Viral
0 -
Hi Viral,
Please note that we don't recommend on using the Admin API (per your shared URL) on the client-side.
For client-side resource listing you can use our Json listing with a shared tag -
http://cloudinary.com/documentation/image_transformations#client_side_resource_lists
This method supports returning the context and not the metadata.
For querying the metadata, you can use our Search API (tier2) -
http://cloudinary.com/documentation/admin_api#search_resources
Hope it helps, let me know if you have any further questions.
Kind regards,
Maor
0 -
Hello Maor
I have an android project.
I am using a signed upload to pass an image caption to my upload option() method.
When the the image is uploaded, i do not get the context in the response resource, however i gat the tags.
MediaManager.get().upload(data.getData())
.option("folder", "images/")
.option("tags", "food")
.option("context", "Pizza")
.callback(new UploadCallback(){
....
}Please clarify, what am i doing wrong
0 -
In order to pass context, it needs to be done using the following:
A map (using the SDKs) or pipe-separated list (for direct API calls) of the key-value pairs of general textual context metadata to attach to an uploaded resource. The context values of uploaded files are available for fetching using the Admin API. For example:
alt=My image❘caption=Profile image
(the=
and❘
characters can be supported as values when escaped with a prepended backslash (\
)). Note that key values are limited to 1024 characters. These details can be found here: https://cloudinary.com/documentation/image_upload_api_reference#upload under Optional parameters.An example using map in Java:
Map<String,String> map= new HashMap<>();
map.put("alt", "pizza");And then pass that map into the context:
MediaManager.get().upload(data.getData())
.option("folder", "images/")
.option("tags", "food")
.option("context",map)
. . .Then the upload will include the result like so:
{ . . . context={custom={alt=pizza}} . . . }
0 -
Hi Daniel,
Thanks for the reply.
I implemented the Map as you instructed in the last message but i got a new error
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
How do i fix it please
0 -
Hi Daniel,
I have an update, i've been able to fix the error (java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String) by storing the map in a String variable before passing it into the context.
Map<String,Object> map = new HashMap<>();
map.put("alt", "pizza");
final String context = map.toString();Then i passed it in like:
MediaManager.get().upload(data.getData())
.option("folder", "images/")
.option("tags", image_price)
.option("context", context)However i want to retrieve the value "pizza" into a String variable, but the response is not in the standard json object format :
{ . . . "context" : {"custom" = {"alt" = pizza}} . . . }
The response i got was:
{ . . . context = {custom = {alt = pizza}} . . . }
How do i read the "alt" value into a String variable.
0 -
Hi Peter,
Please use this code in order to read the context values:
Map<String, HashMap<String,String>> contextResponseData = (HashMap)resultData.get("context"); String value = String.valueOf(contextResponseData.get("custom").get("alt"))); //pizza
Please let me know if it works for you.
Thanks,
Yakir
0 -
Hello Yakir,
Thanks for the feedback
I implemented it as you advised and i was able to read the values, it works fine now
Thanks
0
Post is closed for comments.
Comments
10 comments