I need to access sample_content.xml file name present in DAM into the Java class and i need to store it in a method
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @vineel_k,
You can use mix of Sling and Asset java api to get any asset name.
Resource resource = resourceResolver.getResource("/content/dam/sample_content.xml");
Asset asset = resource.adaptTo(Asset.class);
String assetName = asset.getName();
Having asset object you can also get all other information about specific asset.
Hi @vineel_k,
You can use mix of Sling and Asset java api to get any asset name.
Resource resource = resourceResolver.getResource("/content/dam/sample_content.xml");
Asset asset = resource.adaptTo(Asset.class);
String assetName = asset.getName();
Having asset object you can also get all other information about specific asset.
Below example worked in my local
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.AssetManager;
import com.day.cq.dam.commons.util.DamUtil;
import org.apache.sling.api.resource.ResourceResolver;
public class MyAssetReader {
public void readAssetName(String assetPath, ResourceResolver resourceResolver) {
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(assetPath));
String assetName = asset.getName();
System.out.println("Asset name: " + assetName);
}
}
Views
Likes
Replies
Views
Likes
Replies