Hi @beast42 ,
When it comes to exposing AEM asset data you can consider below 2 options:
- Assets HTTP API [0]
- Sling Servlet - Component/Service
1. Assets HTTP API [0]
Out-Of-The-Box Assets HTTP API implemented as REST API allows for create-read-update-delete (CRUD) operations on digital assets, including on metadata, on renditions, and on comments, together with structured content using Experience Manager Content Fragments.
However, it depends on the requirement whether it meets exact expectations or not based on this, team has to extend/enhance existing feature. For more details please refer [0]
2. Sling Servlet - Component/Service
A Servlet is a class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. For such applications, Servlet technology defines HTTP-specific servlet classes.
By means, through servlet you can implement Sling Servlet to expose data to third party application.
- Implement Servlet/Service which will be responsible for fetching AEM Asset data through QueryBuilder API refer below code snippet for retrieving all properties of an asset
Resource resource;
ValueMap mainProperties;
ValueMap assetMetadataProperties;
Resource metadataResource;
ValueMap jcrProperties;
Resource jcrdataResource;
ValueMap allProperties;
for (Hit hit : result.getHits()) {
//LOGGER.info("\n********Hit path="+hit.getPath()+", title="+hit.getTitle());
resource = hit.getResource();
if(null!=resource){
mainProperties = resource.getValueMap();
// Add JCR Properties
jcrdataResource = resource.getChild("jcr:content");
jcrProperties = ResourceUtil.getValueMap(jcrdataResource);
// Add Metadata properties
metadataResource = resource.getChild("jcr:content/metadata");
assetMetadataProperties = ResourceUtil.getValueMap(metadataResource);
// Adding all together
allProperties = new ValueMapDecorator(new HashMap());
allProperties.putAll(hit.getProperties());
allProperties.putAll(mainProperties); // Includes jcr:created createdDate etc.
allProperties.put("jcr:path",hit.getPath()); //Add Path
allProperties.putAll(jcrProperties);
allProperties.putAll(assetMetadataProperties);
//LOGGER.debug("All Asset Properties="+new Gson().toJson(allProperties));
}
}Retrieving metadata properties eg.
Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam");
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
String formatValue=asset.getMetadataValue("dc:format");
Once you manage to fetch everything as expected, you can then embed it into JSON and expose it to third party.
In this case you will have more control over the other option - One can manipulate the stuff as per need.
[0]: https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/mac-api-assets.html?lang=en
Hope that helps!
Regards,
Santosh