Hi,
Could you please explain how to access and display the DAM asset metadata information programatically in AEM
ex: content/dam/geometrixx/portraits/scott_reynolds.jpg
this image's metadata information.
Thanks in advance.
Vijaya Immadisetty
Solved! Go to Solution.
Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam"); Asset asset = resource.adaptTo(Asset.class); String fileName = asset.getMetadataValue("dc:title"); if (fileName instanceof Object[]) { Object[] titleArray = (Object[]) asset.getMetadata("dc:title"); fileName = (titleArray.length > 0) ? titleArray[0].toString() : ""; } else { fileName = asset.getName(); } Property property = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/original/" + JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA); fileSize = property.getBinary().getSize(); String thumbnailPath = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/" + "you/rendition/to/use").getPath();
Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam"); Asset asset = resource.adaptTo(Asset.class); String fileName = asset.getMetadataValue("dc:title"); if (fileName instanceof Object[]) { Object[] titleArray = (Object[]) asset.getMetadata("dc:title"); fileName = (titleArray.length > 0) ? titleArray[0].toString() : ""; } else { fileName = asset.getName(); } Property property = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/original/" + JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA); fileSize = property.getBinary().getSize(); String thumbnailPath = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/" + "you/rendition/to/use").getPath();
Hi ,
Thank you for your reply.I have followed it and written the servlet as follows
Please find the following code snippet.
@SlingServlet(paths="/bin/myNode")
public class GetRep extends org.apache.sling.api.servlets.SlingAllMethodsServlet{
@Override
protected void doGet(SlingHttpServletRequest slingRequest, SlingHttpServletResponse slingResponse) throws ServerException, IOException
{
PrintWriter out=slingResponse.getWriter();
Resource resource =slingRequest.getResourceResolver().getResource("content/dam/geometrixx/portraits/scott_reynolds.jpg/jcr:content/metadata");
// I have tried using resource path as follows also
// Resource resource =slingRequest.getResourceResolver().getResource("content/dam/geometrixx/portraits/scott_reynolds.jpg");
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
out.println("File name is" +fileName);
String formatValue=asset.getMetadataValue("dc:format");
out.println("Format type is" +formatValue);
}
}
But when requested for the servlet following error coming. could you please help me in resolving this , so that I can get desired response
Cannot serve request to /bin/myNode in com.mycompany.myproject.GetRep
java.lang.NullPointerException at com.mycompany.myproject.GetRep.doGet(GetRep.java:88)
0 (2015-10-15 12:22:01) TIMER_START{Request Processing} 0 (2015-10-15 12:22:01) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message> 0 (2015-10-15 12:22:01) LOG Method=GET, PathInfo=/bin/myNode 0 (2015-10-15 12:22:01) TIMER_START{ResourceResolution} 0 (2015-10-15 12:22:01) TIMER_END{0,ResourceResolution} URI=/bin/myNode resolves to Resource=ServletResource, servlet=com.mycompany.myproject.GetRep, path=/bin/myNode 0 (2015-10-15 12:22:01) LOG Resource Path Info: SlingRequestPathInfo: path='/bin/myNode', selectorString='null', extension='null', suffix='null' 0 (2015-10-15 12:22:01) TIMER_START{ServletResolution} 0 (2015-10-15 12:22:01) TIMER_START{resolveServlet(ServletResource, servlet=com.mycompany.myproject.GetRep, path=/bin/myNode)} 0 (2015-10-15 12:22:01) TIMER_END{0,resolveServlet(ServletResource, servlet=com.mycompany.myproject.GetRep, path=/bin/myNode)} Using servlet com.mycompany.myproject.GetRep 0 (2015-10-15 12:22:01) TIMER_END{0,ServletResolution} URI=/bin/myNode handled by Servlet=com.mycompany.myproject.GetRep 0 (2015-10-15 12:22:01) LOG Applying Requestfilters 0 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl 0 (2015-10-15 12:22:01) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter 0 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.cq.dam.s7imaging.impl.auth.MemoryTokenAuthHandler 0 (2015-10-15 12:22:01) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter 0 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.granite.httpcache.impl.InnerCacheFilter 0 (2015-10-15 12:22:01) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 0 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter 0 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.company.project.sightly.impl.filters.LoggingFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.aem.workflowstep.impl.filters.LoggingFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.sample.sightly.impl.filters.LoggingFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.mycompany.myproject.impl.filters.LoggingFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet 1 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.cq.social.commons.cors.CORSAuthenticationFilter 1 (2015-10-15 12:22:01) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter 1 (2015-10-15 12:22:01) LOG RedirectFilter did not redirect (request extension does not match) 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter 1 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl 1 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.cq.social.commons.security.SaferSlingPostServlet 2 (2015-10-15 12:22:01) LOG Calling filter: com.adobe.granite.requests.logging.impl.RequestLoggerImpl 2 (2015-10-15 12:22:01) LOG Applying Componentfilters 2 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter 2 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter 2 (2015-10-15 12:22:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter 2 (2015-10-15 12:22:01) TIMER_START{com.mycompany.myproject.GetRep#0} 3 (2015-10-15 12:22:01) LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html],order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobile: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=mobiledebug, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobiledebug: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=contentsync, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-contentsync: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), serializer=Config(type=htmlwriter, config={}))} 4 (2015-10-15 12:22:01) TIMER_END{2,com.mycompany.myproject.GetRep#0} 5 (2015-10-15 12:22:01) LOG Applying Error filters 5 (2015-10-15 12:22:01) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 5 (2015-10-15 12:22:01) TIMER_START{handleError:throwable=java.lang.NullPointerException} 10 (2015-10-15 12:22:01) TIMER_END{5,handleError:throwable=java.lang.NullPointerException} Using handler /libs/sling/servlet/errorhandler/default.jsp 12 (2015-10-15 12:22:01) LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html],order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobile: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=mobiledebug, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobiledebug: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=contentsync, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-contentsync: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), serializer=Config(type=htmlwriter, config={}))} 15 (2015-10-15 12:22:01) TIMER_END{15,Request Processing} Dumping SlingRequestProgressTracker Entries
Views
Replies
Total Likes
Hi,
Sorry... and Thank you once again. It is working fine. :)
Please let me know what is the issue. I am also facing the same issue.
Views
Replies
Total Likes