Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

harsingh91
Level 3
Level 3

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

AEM AEM 6.5.1 querybuilder
1 Accepted Solution
vanegi
Correct answer by
Employee
Employee

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();

   }

 

View solution in original post

6 Replies
vanegi
Correct answer by
Employee
Employee

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();

   }

 

View solution in original post

harsingh91
Level 3
Level 3

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"

Arun_Patidar
Community Advisor
Community Advisor

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.

 

 

harsingh91
Level 3
Level 3
Thanks Arun for your answer. But unfortunately I am not a coder, so more detail explanation would be nice.
Arun_Patidar
Community Advisor
Community Advisor
Hi, AEM provide a api/util which provides all the references including template, image, reference pages etc. you can use this to identify the used assets. but you need to write a code to traverse through all the pages and put found assets in Set. Unfortunately you cannot do this using SQL2 or any other query language.
shelly-goel
Community Advisor
Community Advisor

@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