Cloudfront: how to download file instead of displaying in-browser

Hi,

I will be selling digital video files on my online store once it is up and running.

The video files will be available externally for viewing/download via Cloudfront CDN.

The issue that I am having at the moment is that Cloudfront provides me with this sort of URL link per file:

https://[subdomain].cloudfront.net/[file_name.mp4]

This is well and good, except that when the user clicks on the download button on the order confirmation page, instead of a download, they are taken to an in-browser video player.

Granted they are able to right-click and select ‘Save video as’ option, but I would prefer that the video download automatically.

How do I go about doing this?

Thanks.

The HTML spec allows for a “download” attribute to address these scenarios. Unfortunately Webflow has made this a reserved word in the custom attributes area (too many restrictions!). So if you want it to happen you would need to use custom code to add the attribute instead.

<a class="download-link" href="/path/to/download">Download</a>

<script>
  const link = document.querySelector('.download-link');
  link.setAttribute('download', 'OptionalNameOfFile.mp4');
</script>