Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!
SOLVED

Upload Assets to AEM using API

Avatar

Level 4

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 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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