How to make a video or audio file An HTTP response is always downloaded, not played in the browser?

You have some audio and video files that users download, however, depending on the type of file or browser, the browser may try to play the file instead of downloading it. This is undesirable, how can I avoid this? The anchor will be a direct link to the file, if I do not need to create some action for the correct processing of this file. I am using C # ASP.NET MVC.

+3
source share
2 answers

The important parts set the response headers. Set both the content title and the content title. Here is an example:

 Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName)
 Response.AddHeader("Content-Length", lenOfFile)
 Response.ContentType = "application/octet-stream" 
+4
source

HTTP Content-Disposition "attachment":

Content-Disposition: attachment; filename="file.ext"
+2

Source: https://habr.com/ru/post/1764019/


All Articles