Skip to main content
Level 2
Jan 22, 2024 5:55 PM UTC
Solved

aem 6.5 | want to create json file in aem dam programmatically

Hi

i have some json output with me in my java code and that i want to store in a json file in aem dam. Which api should i use ? Asset http api or asset manager api ? And please share code for that

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Saravanan_Dharmaraj
Saravanan_DharmarajAccepted solution
Community Advisor
Jan 22, 2024 6:46 PM UTC

@sumansatija4 if you are creating json inside the AEM, use AssetManager API

AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
if(assetManager != null){
assetManager.createAsset("/location/in/jcr", "application/json", true);
}

 

7 replies

Saravanan_Dharmaraj
Community Advisor
Saravanan_DharmarajCommunity AdvisorAccepted solution
Community Advisor
Jan 22, 2024 6:46 PM UTC

@sumansatija4 if you are creating json inside the AEM, use AssetManager API

AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
if(assetManager != null){
assetManager.createAsset("/location/in/jcr", "application/json", true);
}

 

Translate
Saravanan_Dharmaraj
Community Advisor
Community Advisor
Jan 22, 2024 6:51 PM UTC

One thing to note, if you are using AEM as Cloud service

 

com.day.cq.dam.api.AssetManager.createAsset​(String, InputStream, String, boolean)
In AEM as a Cloud Service, assets should instead take advantage of direct binary access. A discussion of this change as well as an SDK to ease implementation of this new pattern can be found at aem-upload.
Translate
kautuk_sahni
Level 9
Jan 23, 2024 11:54 AM UTC

@sumansatija4  Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Kautuk Sahni
EstebanBustamante
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
Jan 23, 2024 1:58 PM UTC

The practice of programmatically creating 'assets' is discouraged in AEMaaCS due to the Assets Architecture. Further information on this can be found here: https://github.com/adobe/aem-upload?tab=readme-ov-file#background

 

"aem-upload" is recommended for uploading assets to AEMaaCS but I think it is not what you are looking for. I recommend reconsidering the necessity of creating an asset in AEM programmatically. If the goal is to store information (such as JSON), consider using a node or its properties instead.

Hope this helps

Translate
Esteban Bustamante