Get the Asset meta data from the asset node in AEM | AEM Community Blog Seeding
Get the Asset meta data from the asset node in AEM by keshav chaurasiya
Abstract
Get the Assets meta data from the asset node in AEM sling model
@Model(adaptables = {SlingHttpServletRequest.class,Resource.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL, resourceType="myproject/components/content/image")
@Exporter(name="jackson", extensions="json", options= {
@ExporterOption(name = "MapperFeature.SORT_PROPERTIES_ALPHABETICALLY", value = "true")
})
public class ImageModel{
private static Logger LOG = LoggerFactory.getLogger(ImageModel.class);
@SlingObject
private SlingHttpServletRequest request;
@Inject
@Via("resource")
private String image;
}
@Inject
@Via("resource")
private String imageMetaData;
/**
* @return the imageMetaData
*/
public String getImageMetaData() {
String url = request.getRequestURI();
Resource resource = request.getResourceResolver().getResource("/content/dam/my-project/image/image.png");
Asset asset = resource.adaptTo(Asset.class);
String width = asset.getMetadataValue("tiff:ImageWidth");
return this.imageMetaData;
}
}
Read Full Blog
Get the Asset meta data from the asset node in AEM
Q&A
Please use this thread to ask the related questions.
