DAM Asset- How to override dc:title metadata of an Asset | Community
Skip to main content
Anny0505
Community Advisor
Community Advisor
October 29, 2020
Solved

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

  • October 29, 2020
  • 3 replies
  • 3198 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

Hi @anny0505 

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

3 replies

santhosh_kumark
Level 6
October 29, 2020

Hi @anny0505 ,

 

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

 

Thanks,

Santosh

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
October 29, 2020

@1960491_kumarkThank you for the response.

 

Please find the below code 

To create asset in AEM :

asset = AssetImportUtils.createAsset(assetManager, targetPath, fileInputStream, mimeType);

To update asset props

 

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

resource.getResourceResolver().commit();

 

Manjunath_K
Level 7
October 29, 2020

Hi @anny0505 

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) : 

 

 

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

 

 

 

Hope this helps!

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
October 29, 2020

Thank you @manjunath_k. Does your document has title property set?

 

before you upload document to DAm server please open with PDF and right click on the document CLick on Document Properties. Check if your document has properties set. if Not for me also it updating title.

If I have document propertiese set on asset file then it is not overriding.

 

 

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
October 29, 2020

Hi @anny0505 

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

AG