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
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
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();
}
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();
}
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"
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.
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):
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
@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
Views
Likes
Replies