How to download image from DAM using AEM HTTP API? | Community
Skip to main content
Level 2
April 19, 2024
Solved

How to download image from DAM using AEM HTTP API?

  • April 19, 2024
  • 1 reply
  • 1528 views

I am trying to download image thumb nails or original from DAM and show on another web page hosted by another server. Here is my Java servlet:

public void downloadImage(String img_name) throws IOException { String asset_api = "https://dam.company.com/api/assets/products/" + img_name + "/renditions/cq5dam.thumbnail.319.319.png"; try { URL url = new URL(asset_api); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Content-Type", "application/octet-stream"); conn.setRequestProperty("Authorization", "Basic xxxxxxxxx"); conn.setDoOutput(true); System.out.println("resp=" + conn.getResponseCode() + " - " + conn.getResponseMessage()); ...... } catch (Exception ex) { ex.printStackTrace(); } }

But it got error: HTTP/1.1 404 Not Found. I can opened asset_api on the browser directly and it absolutely exists and works fine. Do I need to set permission for running AEM HTTP API for account used in this servlet or need some other settings?

 

Thanks,

James

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 Jam2021

Krati,

 

I found out it's permission issue for the account used in above servlet. When I checked Read ACL for this account in account permission setting page, the above servlet works fine. 

 

Thank you for your time.

James

1 reply

krati_garg
Adobe Employee
Adobe Employee
April 20, 2024

@jam2021 Assets HTTP API are to perform CRUD operations. The above URL will let you read or view the asset but not download it. However, there is a Download Config which essentially enables the Download Servlet and lets you download the Asset via HTTP call.

Enable Asset Download Servlet: https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/assets/manage/download-assets-from-aem#enable-asset-download-servlet:~:text=from%20the%20inbox.-,Enable%20asset%20download%20servlet,-The%20default%20servlet

curl command to download:https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-21528

 

Let me know, if this helps.

Jam2021AuthorAccepted solution
Level 2
April 22, 2024

Krati,

 

I found out it's permission issue for the account used in above servlet. When I checked Read ACL for this account in account permission setting page, the above servlet works fine. 

 

Thank you for your time.

James