question

SimonMinery-1141 avatar image
0 Votes"
SimonMinery-1141 asked PMoran-4376 commented

Force asset download instead of playing in browser

Hi,

I'm currently using Azure Media Services and I'm unable to force a video download instead of in-browser player when clicking the "download" link generated after creating a download locator.
I've got the video.js player working fine with a streaming locator but whatever I do, it seems that I can't for a browser to download the video (well, right click and save work fine but the end user probably won't expect this to download the video directly).
Is there a working example somewhere that shows how to force a client browser download ?
Thank you

azure-media-services
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Were you able to solve this issue? I'm having the same issue. Creating a new locator with a Predefined_DownloadOnly Streaming policy didn't help. Adding the download tag to an anchor <a> tag did not work either (as suggested by DavidBristol). The browser still plays the video rather than saving it.

0 Votes 0 ·
JohnDeutscher-4652 avatar image
0 Votes"
JohnDeutscher-4652 answered

Hi Simon,
I'm somewhat confused on what you are trying to do here. If you are using Media Services, and you already ran an encoding job - you should have an Asset that points to a storage container in storage that has a collection of MP4 files in it.

When you published the content and got back the Streaming Locator - you ended up with a URL that ends with /manifest which provides the top level Smooth Streaming format XML manifest, or you may be likely using the /manifest(format=m3u8-cmaf) version which points to the HLS version of the content. Those manifests are text file descriptions of the smaller 2-second chunks of video that are dynamically generated by the origin server (Streaming Endpoint) to allow for adaptive bitrate streaming. ABR streaming is very different from downloading a file. You can't point to that manifest used for video.js adapative streaming with HLS or DASH and expect it to download the full MP4 file.

If you need a downloadable version of the MP4 file, you need to generate a Shared Access Signature (SAS) URL to the blob file in storage directly and share that with the customer in the browser. That will allow the customer and browser to download the FULL standard MP4 file. You can choose which bitrate to offer to the customer for download directly. That will bypass the origin server's dynamic streaming generation. To get a SAS URL, you have to use the storage blob SDK, or you can request a 'progressive download' URL streaming policy in AMS - see here
https://docs.microsoft.com/en-us/azure/media-services/latest/stream-streaming-policy-concept

If you use a Download only, or the "Predefined_DownloadAndClearStreaming" streaming policy - we provide the full list of downloadable URLs to the MP4's in addition to the streaming HLS and DASH manifest URLs.

It's probably best to look at a site like this and learn how streaming works in general first. Streaming is very different from "downloading".
https://howvideo.works/

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidBristol-1279 avatar image
0 Votes"
DavidBristol-1279 answered

This might be more of a client side question. Or rather how the client handles the MIME type for videos. When Media Services responds to an HTTP GET request for a MP4 file for a download only locator / URL it will respond with the Content-Type: video/mp4 as the MIME type. Browsers and players in the browsers will usually just simply play the video instead of prompting for a download. If you wish to download the video instead, usually you would change the MIME type. However, Media Services doesn't let you do that for videos. As an alternative you could change your HTML code to add the download tag to the anchor <a> tag as per https://actualwizard.com/html-force-download-file.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnDeutscher-4652 avatar image
0 Votes"
JohnDeutscher-4652 answered PMoran-4376 commented

Also refer to this Stack Overflow for some insights on how to control HTML browser behavior when the file is a type that the browser can view.

https://stackoverflow.com/questions/3238657/pdf-to-download-not-link-to-view-download

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you are using a SAS URL to access the file from Azure, is there a way to change the Content-Disposition header as mentioned in the Stack Overflow question? These have to be changed on the Azure side right?

0 Votes 0 ·

did you already try the download attribute in HTML5?

<a href="./directory/yourfile.pdf" download>Download the pdf</a>

https://caniuse.com/?search=download

0 Votes 0 ·
PMoran-4376 avatar image PMoran-4376 JohnDeutscher-4652 ·

Thanks for your response.

I created an anchor tag as you show.

<a href="<SAS URL>" download>Download the video</a>

Where <SAS URL> is the SAS URL I received from Azure. The video is still played rather than downloaded...tested in Chrome version 94.

I thought perhaps it was the Azure Locator that was the problem as the Locator Streaming policy was ClearStreamingOnly, so I created a new Locator with a Streaming policy of DownloadOnly but that didn't seem to make a difference.

0 Votes 0 ·
Show more comments