Skip to main content
Level 2
Sep 13, 2024 8:39 AM UTC

How to implement Servlet to find smart tags attached with an image?

Hi, 

I just want to know how to implement a servlet to find search the smart tags attached with an image.

Is there we have to make changes in a already present servlet or to create a new servlet?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

MukeshYadav_
Community Advisor
Community Advisor
Sep 13, 2024 10:10 AM UTC

Hi @prachimathur ,

Adapt the image path as asset and try to get the required properties from Asset metadata. You may cross check the property name from crxde node

Ref https://www.linkedin.com/pulse/get-asset-meta-data-from-node-aem-keshav-chaurasiya

Thanks

Translate
Level 2
Sep 13, 2024 10:51 AM UTC

Hi,

This way suggests the sling model code to get the metadata but is there any way we can get smart tags through servlet.

 

Translate
arunpatidar
Community Advisor
Community Advisor
Sep 13, 2024 10:39 AM UTC

Hi @prachimathur 
Can you check the CRXDE, to see where the smart tags are stored for a image.

Then create a servlet which accept image path and you can serach for the smart tag for that assets,

basic code example

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DownloadAssetsImage.java 

 

Resource assetResource = resourceResolver.getResource(assetPath); if (assetResource != null) { // Get the Asset object from the resource Asset asset = assetResource.adaptTo(Asset.class); if (asset != null) { // Fetch the smart tags from the metadata node of the asset String[] tagIds = asset.getMetadataValue("predictedTags"); // Get the TagManager from the resource resolver TagManager tagManager = resourceResolver.adaptTo(TagManager.class); // Convert tag IDs to Tag objects if (tagIds != null && tagManager != null) { for (String tagId : tagIds) { Tag tag = tagManager.resolve(tagId); if (tag != null) { tags.add(tag); } } } }
Translate
Arun Patidar
kautuk_sahni
Level 9
Sep 25, 2024 12:30 PM UTC

@prachimathur Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni