Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

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

Avatar

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
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

9 Replies

Avatar

Correct answer by
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();

   }

 

Avatar

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"

Avatar

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.

 

 



Arun Patidar

Avatar

Level 3
Thanks Arun for your answer. But unfortunately I am not a coder, so more detail explanation would be nice.

Avatar

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.


Arun Patidar

Avatar

Level 1

Hi Arun,

 

I'm looking at this now (https://experienceleague.adobe.com/docs/experience-cloud-kcs/kbarticles/KA-19249.html?lang=en), but if I choose an asset that visibly has many references e.g. here (under the 'References' tab):

 

http://host:port/mnt/overlay/dam/gui/content/assets/metadataeditor.external.html?_charset_=utf-8&ite...

 

I cannot see its references as JSON through the API: http://host:port/libs/wcm/core/content/reference.json?path=/content/dam/path/to/my.pdf

The result I see is empty

 

{"assets":[]}

 

Any idea why this might happen?

 

Thanks

Avatar

Community Advisor

This api is used for the pages but you are using this for the page

Assets might not have other assets references in your case.



Arun Patidar

Avatar

Level 1

Can you please clarify your last comment a bit? I'm not sure what this means ... "api is used for the pages but you are using this for the page" - what's the difference between 'pages' and 'page' ?

Do you mean that the API actually works the other way around -- that if I give it a .JPG in the path= it will give me

  • the other assets that this .JPG asset is referencing
    and NOT
  • the web pages where this .JPG asset is being referenced ? 

Avatar

Employee 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