Expand my Community achievements bar.

SOLVED

Use ASSET API how to iterate a parent node in AEM?

Avatar

Level 2

I have parent asset node inside the AEM CRXDE (/content/dam/parent). inside the parent node folder multiple child nodes are there .

Using Asset API how can i iterate the child nodes.?

After that i have to read/write properties.!

1 Accepted Solution

Avatar

Correct answer by
Level 9

Refer to https://helpx.adobe.com/experience-manager/using/graniteAPI.html and https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/diff-previ...

or do something like this

https://raw.githubusercontent.com/Adobe-Consulting-Services/acs-aem-commons/master/bundle/src/main/j...

final Iterator<Resource> assets = findAssets(resourceResolver, "YOUR CUSTOM DAM PATH");

  while (assets.hasNext()) {

  final Asset asset = assets.next().adaptTo(Asset.class);

 

  }

View solution in original post

3 Replies

Avatar

Correct answer by
Level 9

Refer to https://helpx.adobe.com/experience-manager/using/graniteAPI.html and https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/diff-previ...

or do something like this

https://raw.githubusercontent.com/Adobe-Consulting-Services/acs-aem-commons/master/bundle/src/main/j...

final Iterator<Resource> assets = findAssets(resourceResolver, "YOUR CUSTOM DAM PATH");

  while (assets.hasNext()) {

  final Asset asset = assets.next().adaptTo(Asset.class);

 

  }

Avatar

Level 2

Thanks :-) It is working but how to read/write the properties from asset.?

Avatar

Level 9

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();