DAM Asset- How to override dc:title metadata of an Asset

Avatar

Avatar

annyreddy

Avatar

annyreddy

annyreddy

29-10-2020

Hi All,

 

I am using  Asset api to create asset and assigning metadata propertiese  by adopting asset.

When I assign prperty to dc;title if any document has defined title on it is not able to assign my custom title.

 

Could you please suggest how to resolve this issue. Same thing is happening for dc:description field too. I need to override this with custom data.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Anudeep_Garnepudi

Avatar

Anudeep_Garnepudi

Anudeep_Garnepudi

29-10-2020

Hi @annyreddy 

resource.getChild(String) will take relative path. Just see the below updated code. No need of "asset.getPath() +".

Resource resource = asset.adaptTo(Resource.class);
Resource metaResource = resource.getChild(DAMConstants.JCR_CONTENT_METADATA);
ModifiableValueMap modifiableValueMap = metaResource.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("dc:title", "Title");

resource.getResourceResolver().commit();

AG

Answers (2)

Answers (2)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

29-10-2020

Hi @annyreddy 

I am able update asset meta data title using below code. check whether required permission is set for the service user which you are using. 

 

Resource metaResource = resourceResolver.getResource( "/content/dam/we-retail/en/products/apparel/gloves/Gloves.jpg/jcr:content/metadata");
ModifiableValueMap modifiableValueMap = metaResource.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("dc:title", "Title After Update");
if(resourceResolver.hasChanges()){
resourceResolver.commit();
}

 

Asset Before Update (with title configured) : 

metabefore.png

 

 

Asset After Update (using service resource resolver in backend) :

metaafter.png 

 

 

Hope this helps!

Avatar

Avatar

santhosh_kumark

Avatar

santhosh_kumark

santhosh_kumark

29-10-2020

Hi @annyreddy ,

 

Can you share the sample code how are you trying to override to understand it better.

 

Thanks,

Santosh