Upload Assets to AEM using API | Community
Skip to main content
chetan001
November 25, 2021
Solved

Upload Assets to AEM using API

  • November 25, 2021
  • 2 replies
  • 1442 views

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.
Best answer by arunpatidar

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

2 replies

Kiran_Vedantam
Community Advisor
Community Advisor
November 25, 2021
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 27, 2021

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
chetan001
chetan001Author
November 28, 2021

Thanks Arun for your input