Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Mayank_Gandhi
Mayank_GandhiAccepted solution
Adobe Employee
October 3, 2022

@pawanpatilrocks I have not tried using metadata id. But if you have the resource path then:

 

Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam"); 
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
if (fileName instanceof Object[]) {
Object[] titleArray = (Object[])
asset.getMetadata("dc:title"); fileName = (titleArray.length > 0) ? titleArray[0].toString() : ""; }
else { fileName = asset.getName(); } Property property = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/original/" + JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA); fileSize = property.getBinary().getSize(); String thumbnailPath = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/" + "you/rendition/to/use").getPath();

  

public interface AssetMetadata
or

To get AssetMetadata, use Asset.getAssetMetadata()

 Example:

 Asset asset = assetManager.getAsset("/path/to/asset/document.pdf");

 // get metadata
 AssetMetadata assetMetadata = asset.getAssetMetadata();

1 reply

Mayank_Gandhi
Adobe Employee
Mayank_GandhiAdobe EmployeeAccepted solution
Adobe Employee
October 3, 2022

@pawanpatilrocks I have not tried using metadata id. But if you have the resource path then:

 

Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam"); 
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
if (fileName instanceof Object[]) {
Object[] titleArray = (Object[])
asset.getMetadata("dc:title"); fileName = (titleArray.length > 0) ? titleArray[0].toString() : ""; }
else { fileName = asset.getName(); } Property property = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/original/" + JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA); fileSize = property.getBinary().getSize(); String thumbnailPath = asset.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT + "/renditions/" + "you/rendition/to/use").getPath();

  

public interface AssetMetadata
or

To get AssetMetadata, use Asset.getAssetMetadata()

 Example:

 Asset asset = assetManager.getAsset("/path/to/asset/document.pdf");

 // get metadata
 AssetMetadata assetMetadata = asset.getAssetMetadata();
Translate