Expand my Community achievements bar.

SOLVED

Download option Functionality.

Avatar

Level 4

So in one of the scenario we are having an image/video and download option for it. So whenever we click on that download button/logo the image gets downloaded. We checked this thing on Local author and local publish instance and it worked as expected. But on DEV, STAGE and PROD it worked only on author instance. It didn't work as expected on publisher and dispatcher instances.

Issue: When we click on that download option, the image/video opens in new tab, but doesn't get downloaded.

 

Any insights on this.

 

Thanks,

Shreyas.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Shreyas_tm ,

These are dispatcher rules we can write in vhost file

eg.  dispatcher/src/conf.d/available_vhosts/projectname.vhost

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html

# Other directives

<LocationMatch "\.(?i:jpg|jpeg|png|gif|bmp|webp)$">
ForceType application/octet-stream
Header set Content-Disposition "attachment; filename=\"default-image.jpg\""
</LocationMatch>

<LocationMatch "\.(?i:mp4|avi|mov|mkv)$">
ForceType application/octet-stream
Header set Content-Disposition "attachment; filename=\"default-video.mp4\""
</LocationMatch>

# Other directives
</VirtualHost>

Thanks

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @Shreyas_tm ,

We need to set Content-Disposition Header something like Content-Disposition: attachment; filename="filename.jpg"

where

  • attachment   - to download the asset
  • inline         - to open in browser

Rule can be written path specific with help of LocationMatch.

For example

 

<LocationMatch "\.(?i:jpg|jpeg|png|gif|bmp|webp)$">
  ForceType application/octet-stream
  Header set Content-Disposition "attachment; filename=\"default-image.jpg\""
</LocationMatch>

<LocationMatch "\.(?i:mp4|avi|mov|mkv)$">
  ForceType application/octet-stream
  Header set Content-Disposition "attachment; filename=\"default-video.mp4\""
</LocationMatch>

 

References https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/content-disposition-on-aem...

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-6-5-asset-direct-link-...

Thanks

Avatar

Level 4

Hi @MukeshYadav_  I didn't get where do we need to add that piece of code. I tried finding it. But didn't get. Can you please help me on this.

 

Thanks,

shreyas.

Avatar

Correct answer by
Community Advisor

Hi @Shreyas_tm ,

These are dispatcher rules we can write in vhost file

eg.  dispatcher/src/conf.d/available_vhosts/projectname.vhost

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html

# Other directives

<LocationMatch "\.(?i:jpg|jpeg|png|gif|bmp|webp)$">
ForceType application/octet-stream
Header set Content-Disposition "attachment; filename=\"default-image.jpg\""
</LocationMatch>

<LocationMatch "\.(?i:mp4|avi|mov|mkv)$">
ForceType application/octet-stream
Header set Content-Disposition "attachment; filename=\"default-video.mp4\""
</LocationMatch>

# Other directives
</VirtualHost>

Thanks

Avatar

Community Advisor

Hi,

Please use selector in the url e.g. 'download' to differentiate normal and downloadable assets.

 



Arun Patidar