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

Avatar

Avatar
Give Back 5
Level 2
harsingh91
Level 2

Likes

9 likes

Total Posts

38 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Ignite 3
Give Back
Ignite 1
View profile

Avatar
Give Back 5
Level 2
harsingh91
Level 2

Likes

9 likes

Total Posts

38 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Ignite 3
Give Back
Ignite 1
View profile
harsingh91
Level 2

01-07-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 5
Employee
vanegi
Employee

Likes

392 likes

Total Posts

378 posts

Correct reply

148 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile

Avatar
Give Back 5
Employee
vanegi
Employee

Likes

392 likes

Total Posts

378 posts

Correct reply

148 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile
vanegi
Employee

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

   }

 

Answers (2)

Answers (2)

Avatar

Avatar
Boost 250
MVP
shelly-goel
MVP

Likes

250 likes

Total Posts

410 posts

Correct reply

107 solutions
Top badges earned
Boost 250
Affirm 100
Give Back 25
Ignite 3
Give Back 10
View profile

Avatar
Boost 250
MVP
shelly-goel
MVP

Likes

250 likes

Total Posts

410 posts

Correct reply

107 solutions
Top badges earned
Boost 250
Affirm 100
Give Back 25
Ignite 3
Give Back 10
View profile
shelly-goel
MVP

03-07-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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,329 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,329 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

01-07-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.