Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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);
}

 

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

@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);
}

 

Avatar

Community Advisor

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.

Avatar

Community Advisor

@SumanSatija4 yes, please see the second message i sent for more information.

Avatar

Administrator

@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.



Kautuk Sahni

Avatar

Community Advisor

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.

EstebanBustamante_0-1706018000384.png

Hope this helps



Esteban Bustamante