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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Edit MetaData Properties in DAM(CRXDE)

Avatar

Level 3

Hi,

I've uploaded some documents along with some metadata properties(file uploaded using Asset Manager) in CRXDE-DAM. I need to update the meta data properties  from client side and save it again in DAM. How we can perform this programmatically in CQ ?  I've attached the screenshot of DAM uploaded file with meta data properties.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

A sample code:

String resourcePath = "/content/dam/geometrixx-outdoors/banners/adventure.jpg"; resourceResolver= resolverFactory.getAdministrativeResourceResolver(null); Resource res = resourceResolver.getResource(resourcePath); Resource metadataRes =res.getChild("jcr:content/metadata"); ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class); //set metadata map.put("dc:samplemetadata", "sample metadata"); resourceResolver.commit(); //get metadata String metadata=map.get("dc:samplemetadata").toString();   

Hope this helps.

View solution in original post

0 Replies

Avatar

Level 9

Hi Nandhini ,

   AEM is rest based. On client side update using http call.

Thanks

Avatar

Level 3

Hi,

I'm new to CQ. Can you elaborate.?  

Currently what I've done is after uploading the file i'll  list all the uploaded file along with values stored in metadata in one page (Screen Shot  Attached) and on clicking the row I'll edit some field names and update the  newly edited values into CQ DAM(for the same file where we clicked), I've implemented by uploading the file again and do the modification and save it back to CRXDE dam structure(Its like uploading the file again by replacing the old file in CRXDE). My doubt is 'Is there any other possible way to do the modification without uploading the file again and save it back to DAM in CRXDE)

Thanks and Regards,

Nandhini 

Avatar

Level 3

Hi,

I'm new to CQ. Can you elaborate.?  

Currently what I've done is after uploading the file i'll  list all the uploaded file along with values stored in metadata in one page (Screen Shot  Attached) and on clicking the row I'll edit some field names and update the  newly edited values into CQ DAM(for the same file where we clicked), I've implemented by uploading the file again and do the modification and save it back to CRXDE dam structure(Its like uploading the file again by replacing the old file in CRXDE). My doubt is 'Is there any other possible way to do the modification without uploading the file again and save it back to DAM in CRXDE)

Thanks and Regards,

Nandhini 

Avatar

Level 3

Hi,

I'm new to CQ. Can you elaborate.?  

Currently what I've done is after uploading the file i'll  list all the uploaded file along with values stored in metadata in one page (Screen Shot  Attached) and on clicking the row I'll edit some field names and update the  newly edited values into CQ DAM(for the same file where we clicked), I've implemented by uploading the file again and do the modification and save it back to CRXDE dam structure(Its like uploading the file again by replacing the old file in CRXDE). My doubt is 'Is there any other possible way to do the modification without uploading the file again and save it back to DAM in CRXDE)

Thanks and Regards,

Nandhini 

Avatar

Community Advisor

Hi,

You can use script to upload file so you don't have to do manually. You can write a script which will read all file paths and upload to crx/de DAM path.

 

#!/bin/bash file=path.txt SOURCE="http://localhost:4502" # The user credentials on the source server (username:password) SOURCE_CRED="admin:admin" # add filters while IFS= read -r line do curl -u admin:admin -T $line http://localhost:4502/content/$line done < "$file"

In this script, it'll read paths of file defined in path.txt and push it to AEM. It's a shell script so run it on windows you can install cygwin.

Workaround : Create a folder and put all dam assets that you want to upload. Add path.txt in that folder and add asset names(don't miss out extension) in text file. Then, add shell script in folder and save it with .sh extension.

If you're using windows, download cygwin to run shell script.

Script will read all files and will update on crx/de DAM.

 

Thanks,

Himanshu

Avatar

Level 3

Hi Himanshu,

Thanks for your time to reply to my question.

But my doubt is , how we can edit the metadata property values which is already stored in DAM. I mean I've uploaded some PDF files along with metadata values in DAM and will list all the file name along with metadata values in jsp and now i need to edit the metadata values programmatically and save it back to DAM. Code which i used to upload files and  add metadata property is,

AssetManager assetManager = (AssetManager) resourceResolver.adaptTo(AssetManager.class); Asset asset = assetManager.getAssetForBinary(DamUtil.assetToBinaryPath(assetPath)); String mimeType =this.mimeTypeService.getMimeType(fileName); asset = assetManager.createAsset(assetPath,file1, mimeType, true); Resource metadataRes = asset.adaptTo(Resource.class).getChild("jcr:content/metadata"); ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class); map.put("dc:podname", podname); map.put("dc:actualDeliveryDate", actualDeliveryDate);
Can we take the asset path[ /content/dam/nextgen/Ehub-POD/HK/POD Argentina.pdf ] and edit the metadata values ? If so can you explain  me how to do it ?

 

Thanks ,

Nandhini 

Avatar

Correct answer by
Community Advisor

A sample code:

String resourcePath = "/content/dam/geometrixx-outdoors/banners/adventure.jpg"; resourceResolver= resolverFactory.getAdministrativeResourceResolver(null); Resource res = resourceResolver.getResource(resourcePath); Resource metadataRes =res.getChild("jcr:content/metadata"); ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class); //set metadata map.put("dc:samplemetadata", "sample metadata"); resourceResolver.commit(); //get metadata String metadata=map.get("dc:samplemetadata").toString();   

Hope this helps.

Avatar

Level 3

Thank you Himanshu 🙂  Your code helped me  to solve the issue.