Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Need to fetch metadata properties of assets through sling models

Avatar

Avatar
Validate 1
Level 2
lovepreetk75597
Level 2

Likes

3 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 3
View profile

Avatar
Validate 1
Level 2
lovepreetk75597
Level 2

Likes

3 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 3
View profile
lovepreetk75597
Level 2

06-05-2019

Hi,

I have one requirement where i need fetch asset path or asset's metadata properties using sling models. Does anyone have any idea how could we achieve this.

Regards,

Lovepreet

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,139 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,139 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

06-05-2019

you can try something like below:

@Model(adaptables = { Resource.class, SlingHttpServletRequest.class })

public class ImageMetadataModel {

@Inject

@Optional

private String assetPath;

@SlingObject

private ResourceResolver resourceResolver;

public String getProperty () {

Resource resource = resourceResolver.getResource(assetPath);

String property = “”;

if (resource != null) {

Asset asset = resource.adaptTo(Asset.class);

property = asset.getMetadataValue("dc:title");

}

return property;

}

}

Answers (1)

Answers (1)

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

06-05-2019

As Arun has pointed out - you must use the Asset API to perform this use case.