How to download dam images from sightly code? | Community
Skip to main content
Level 6
Jan 6, 2023 6:10 PM UTC
Solved

How to download dam images from sightly code?

Hi,

I tried the code mentioned below.

<a href="/content/dam/wknd/images/sample.jpg" download> <img src="/content/dam/wknd/images/sample.jpg" alt="sample" width="104" height="142"> </a>

 This piece of code opens the image in a new tab, it doesn't download the image to my system.

 

How to achieve this functionality.

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
New Participant
Jan 8, 2023 2:03 PM UTC

you need to write a filter which add those headers when images are requested.

Arun Patidar

7 replies

Level 3
Jan 9, 2023 1:23 PM UTC

Please try 

 

There is an OSGi Configuration in Felix console named "Apache Sling Content
Disposition Filter" which controls Content Disposition for different mime types based on the path 
 

 

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-assets/asset-direct-link-is-downloading-not-open-asset-on-new-tab/td-p/290097

Translate
arunpatidar
New Participant
Jan 6, 2023 8:06 PM UTC

you have to look for Content-Disposition header to achieve that

EXAMPLE, That file is send with these headers:

Content-Type: application/force-download
Content-Disposition: attachment; filename=bike_chase-wallpaper-2560x1600.jpg

 

Translate
Arun Patidar
Ronnie09Author
Level 6
Jan 6, 2023 9:13 PM UTC

@arunpatidar 

You mean I have to write servlet and send these data through that servlet.... Content-Type: application/force-download

Content-Disposition: attachment; filename


This code I tried.. it is downloading the image but it shows, image format not supported

try { ResourceResolver resourceResolver = request.getResourceResolver(); Resource assetResource = resourceResolver.getResource("/content/dam/wknd-shared/en/contributors/ayo-ogunseinde-237739.jpg"); Set<Resource> assetSet = new HashSet<>(); assetSet.add(assetResource); response.setContentType("application/force-download"); response.setHeader("Content-Disposition", "attachment; filename=ayo-ogunseinde-237739.jpg"); assetDownloadService.assetDownload(assetResource, assetSet, true, false, false, null, null, "ayo-ogunseinde-237739.jpg", StringUtils.EMPTY, response.getOutputStream()); } catch (Exception e) { e.printStackTrace(); }

 

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Jan 8, 2023 2:03 PM UTC

you need to write a filter which add those headers when images are requested.

Translate
Arun Patidar