How to find the list of all images used in content pages | Community
Skip to main content
harsingh91
Level 3
July 1, 2021
Solved

How to find the list of all images used in content pages

  • July 1, 2021
  • 3 replies
  • 7637 views

Hello Team,

 

I am using AEM 6.5.

 

How can I find the list of all the images from DAM which are used in content pages using AEM query.

We have many images in DAM but not all are getting used on pages. I have tried basic (Xpath, SQL2) queries using https://gist.github.com/floriankraft/8b3720464318cd5cd9e2 but couldn't succeeded.

 

Thanks in advance,

harsingh

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by vanegi

Hello, if you need to search in a java class there is class called AssetReferenceSearch . It's constructor takes the node (content node of the page ) to search under , path where the assets are stored (can be /content/dam ) and Resource Resolver.

Reference : http://wemcode.wemblog.com/get_asset_reference_in_page

 

 String Pagepath = "/content/we-retail/en"; //This would be your page path

  Resource r = resourceResolver.getResource(Pagepath+"/"+JcrConstants.JCR_CONTENT);

  Node n = r.adaptTo(Node.class);

  AssetReferenceSearch ref = new AssetReferenceSearch(n,DamConstants.MOUNTPOINT_ASSETS,resourceResolver);

  Map<String,Asset> allref = new HashMap<String,Asset>();

   allref.putAll(ref.search());

   for (Map.Entry<String, Asset> entry : allref.entrySet()) {

  String val = entry.getKey();

  out.println(val+"<br>"); // Path of all Asset ref in page

  Asset asset = entry.getValue();

   }

 

3 replies

vanegi
Adobe Employee
vanegiAdobe EmployeeAccepted solution
Adobe Employee
July 1, 2021

Hello, if you need to search in a java class there is class called AssetReferenceSearch . It's constructor takes the node (content node of the page ) to search under , path where the assets are stored (can be /content/dam ) and Resource Resolver.

Reference : http://wemcode.wemblog.com/get_asset_reference_in_page

 

 String Pagepath = "/content/we-retail/en"; //This would be your page path

  Resource r = resourceResolver.getResource(Pagepath+"/"+JcrConstants.JCR_CONTENT);

  Node n = r.adaptTo(Node.class);

  AssetReferenceSearch ref = new AssetReferenceSearch(n,DamConstants.MOUNTPOINT_ASSETS,resourceResolver);

  Map<String,Asset> allref = new HashMap<String,Asset>();

   allref.putAll(ref.search());

   for (Map.Entry<String, Asset> entry : allref.entrySet()) {

  String val = entry.getKey();

  out.println(val+"<br>"); // Path of all Asset ref in page

  Asset asset = entry.getValue();

   }

 

harsingh91
Level 3
July 1, 2021

Thank you Vanegi for your answer.

But can this be achieved by using query builder in CRXDE

Like for an example:

SELECT * FROM [nt: unstructured] AS node WHERE ISDESCENDANTNODE (node, "/ search / in / path" ) AND NAME () = "nodeName"

arunpatidar
Community Advisor
Community Advisor
July 1, 2021

Hi,

you can find the assets reference using OOTB api

make a post request to /libs/wcm/core/content/reference.json with path=pagepath as form data.

 

you can combine the query builder result with this to get assets from the Front end side.

If you already have a groovy console in AEM, then it will be easy to do everything there uisng groovy.

 

 

Arun Patidar
harsingh91
Level 3
July 1, 2021
Thanks Arun for your answer. But unfortunately I am not a coder, so more detail explanation would be nice.
shelly-goel
Adobe Employee
Adobe Employee
July 3, 2021

@harsingh91  You would be able to fetch all the node paths having a DAM Asset reference with below query:

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content/wknd]) and s.[fileReference] is not null

fileReference property on these node results contains the Asset Path