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?
Views
Replies
Total Likes
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
Hi,
This way suggests the sling model code to get the metadata but is there any way we can get smart tags through servlet.
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);
}
}
}
}
@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!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies