fetch image using JCR or Query Builder
Hi,
I have implemented simple program for fetching image using JCR.
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource("/content/dam/geometrixx-media/articles/bored.jpeg");
Asset asset = res.adaptTo(Asset.class);
I am able to display image on JSP as asset.getPath() gives me path of image. But all this works fine only if I mention complete path of image. If I provide only name of the image (bored.jpeg) then it does not work.
As a solution to this problem I used query builder API. Followed link http://helpx.adobe.com/experience-manager/using/aem-dam-image-components.html
But code snippet provided in this link retrieves all images matching to search criteria. Because I wanted to search for particular image I updated query parameters as follows,
Map<String, String> map = new HashMap<String,String>();
map.put("type", "dam.Asset");
map.put("property", "cq:name");
map.put("property.value", "ai.jpeg");
qb=resource.getResourceResolver().adaptTo(QueryBuilder.class);
Query query = qb.createQuery(PredicateGroup.create(map), session);
SearchResult sr= query.getResult();
String assetPath=null;
// iterating over the results
Iterator<Resource> resources = sr.getResources();
while(resources.hasNext() ) {
Resource res = resources.next();
Asset asset = res.adaptTo(Asset.class);
String Path = asset.getPath();
which led to an exception because Asset object is null. Resource object gives me path as follows "/content/dam/geometrixx-media/articles/ai.jpeg/jcr:content" I am not getting why path is appended with /jcr:content when I searched for particular image. This does not happen when I search for images matching jpeg type or some other general search as given in following link http://helpx.adobe.com/experience-manager/using/aem-dam-image-components.html
Kindly help me in resolving this issue.
Thanks,
Manju