Skip to main content
Level 2
September 13, 2024

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

  • September 13, 2024
  • 4 replies
  • 746 views

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

kautuk_sahni
Employee
September 25, 2024

@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!

Kautuk Sahni
arunpatidar
New Participant
September 13, 2024

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); } } } }
Arun Patidar
MukeshYadav_
New Participant
September 13, 2024

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

Level 2
September 13, 2024

Hi,

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