April 27, 2020
Estimated Post Reading Time ~

Programmatically Set/Get the metadata of an Asset

The Adobe Experience Manager(AEM) version referred here is 5.6.1

@Reference
private ResourceResolverFactory resolverFactory;

ResourceResolver resourceResolver =null;
try
{
String resourcePath = "/content/dam/geometrixx-outdoors/banners/adventure.jpg";
resourceResolver= resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource(resourcePath);

Resource metadataRes =res.getChild("jcr:content/metadata");
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);

//set metadata
map.put("dc:samplemetadata", "sample metadata");
resourceResolver.commit();

//get metadata

String metadata=map.get("dc:samplemetadata").toString();

}catch(Exception e)
{

}finally
{
resourceResolver.close();
}




Dependency in pom.xml

<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.