Force asset download instead of playing in browser

Simon Minery 1 Reputation point
2021-09-04T11:00:38.453+00:00

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
Azure Media Services
A group of Azure services that includes encoding, format conversion, on-demand streaming, content protection, and live streaming services.
302 questions
{count} votes

3 answers

Sort by: Most helpful
  1. John Deutscher 241 Reputation points
    2021-09-07T17:46:59.567+00:00

    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://learn.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/

    0 comments No comments

  2. David Bristol 971 Reputation points Microsoft Employee
    2021-09-08T18:42:09.717+00:00

    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.

    0 comments No comments

  3. John Deutscher 241 Reputation points
    2021-10-07T17:41:06.787+00:00

    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