How do you make a file available for download and browser viewing? As an example, files of type pdf and mp4 .
When I want to make the file available for download, I simply use the following routine:
public ActionResult Download(string fileName)
{
var path = Server.MapPath("~/Arquivos/Biblioteca/") + fileName;
return File(path, MimeMapping.GetMimeMapping(path), Path.GetFileName(path));
}
When trying to make it available to be viewed in the browser I tried the following:
public ActionResult OpenFile(string fileName)
{
var path = Server.MapPath("~/Arquivos/Biblioteca/") + fileName;
return File(path, MimeMapping.GetMimeMapping(path));
}
The difference is that I did not tell the property referring to the file name to download.
On my computer (debug mode mode) the video and PDF are shown in the browser as expected.
But when trying to make it available on the server, both are not opened and the file is then downloaded.
Firstly I was trying to open the file directly, without passing a controller and an action, so time was right, not time, because it gave a file error not found. Probably due to the size of the name.
For this to happen, I needed to register the mime on the server's IIS video server.
But as I said, it is usually a mistake and for good practice, I do not want to access the file directly.
So, how do you make the files available for viewing in your browser, when possible?