Skip to main content
chetan001
Level 3
Nov 25, 2021 2:30 PM UTC
Solved

Upload Assets to AEM using API

Hi All,

 

I am integrating AEM with rest service which is providing image/asset urls .  using this url ,I have to get image and this image should upload to AEM DAM System.

 

I am planning to  download image in aem root/folder path using http client api. Then using AEM Assets http Api  will upload to dam folder.

 

Is this approach fine ? 

 

Could you please share best approach to implement this kind of scenario.

 

Appreciate your comments.

 

@amit-tiwari 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
Community Advisor
Nov 27, 2021 7:10 PM UTC

Hi

you can use Asset Java API as well to fetch as inputstream and create assets e.g. below code

 

public String importAsset(String assetUri, ResourceResolver resolver){
    AssetObj assestObj = requestService.getAsset(assetUri);
    InputStream is = assestObj.getAssetAsInputStream();
    String mimeType = assestObj.getMimeType();
    String assetsPath = assestObj.getAssetDamPath();
    AssetManager am = resolver.adaptTo(AssetManager.class);
    Asset asset = am.createAsset(assetsPath, is, mimeType, true);
    resolver.commit();
}
Arun Patidar

3 replies

Kiran_Vedantam
Community Advisor
Community Advisor
Nov 25, 2021 2:46 PM UTC
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
Nov 27, 2021 7:10 PM UTC

Hi

you can use Asset Java API as well to fetch as inputstream and create assets e.g. below code

 

public String importAsset(String assetUri, ResourceResolver resolver){
    AssetObj assestObj = requestService.getAsset(assetUri);
    InputStream is = assestObj.getAssetAsInputStream();
    String mimeType = assestObj.getMimeType();
    String assetsPath = assestObj.getAssetDamPath();
    AssetManager am = resolver.adaptTo(AssetManager.class);
    Asset asset = am.createAsset(assetsPath, is, mimeType, true);
    resolver.commit();
}
Translate
Arun Patidar
chetan001
chetan001Author
Level 3
Nov 28, 2021 1:32 PM UTC

Thanks Arun for your input

Translate