Expand my Community achievements bar.

SOLVED

How can i extract the metadata of an asset ?

Avatar

Level 2

Hi !!!

I'm on AEM as a cloud service. I can retrieve the asset but...

 

ResourceResolver rs = request.getResourceResolver();
Asset desktopImage = rs.getResource(srcFromImage).adaptTo(Asset.class);

 


How can I retrieve the asset properties of that file, such as title, description, etc.?

I tried with 

 

desktopImage.getMetadataValue("dc:title")
//Cannot evaluate because of compilation error(s): The method getMetadataValue(String) is undefined for the type Asset.

 


Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 2

RESOLVED !

I imported import 'com.adobe.granite.asset.api.Asset' instead of 'com.day.cq.dam.api.Asset'

        String title;
        
        ResourceResolver rs = request.getResourceResolver();
        Asset desktopImage = rs.getResource(srcFromImage).adaptTo(Asset.class);

        title = desktopImage.getMetadataValue(DamConstants.DC_TITLE);

        return title != null ? title : "";

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

RESOLVED !

I imported import 'com.adobe.granite.asset.api.Asset' instead of 'com.day.cq.dam.api.Asset'

        String title;
        
        ResourceResolver rs = request.getResourceResolver();
        Asset desktopImage = rs.getResource(srcFromImage).adaptTo(Asset.class);

        title = desktopImage.getMetadataValue(DamConstants.DC_TITLE);

        return title != null ? title : "";