Expand my Community achievements bar.

SOLVED

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

Avatar

Community Advisor

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @Anny0505 ,

 

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

 

Thanks,

Santosh

Avatar

Community Advisor

@Deleted Account_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();

 

Avatar

Level 8

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

metabefore.png

 

 

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

metaafter.png 

 

 

Hope this helps!

Avatar

Community Advisor

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.

 

annyreddy_0-1603999356326.png

 

Avatar

Level 8

Hi @Anny0505 

 

I tried the steps which you provided i.e. uploading pdf file with having title on DAM, i was able to update that pdf asset tile in backend & was not able to reproduce the issue which you are facing. try to check ModifiableValueMap in debug mode/printing in log after putting new title to it.

 

sample-doc.png

Avatar

Community Advisor

Thank you @Manjunath_K. I am using servlet and using request onject. still it is not updating title.

 

I am getting below error  com.adobe.xmp.worker.files.ncomm.XMPFilesNComm [XMPFilesProcessor.exe-4316] vcfoundation::ncomm::NCException: XMP Error 9: File could not be saved
race: 1 011330A0
2 01133128
3 011320A5
4 0113275E
5 01132572
6 0113166C

Avatar

Correct answer by
Community Advisor

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