Partial content in .NET Core MVC (for video/audio streaming)

There will be an enableRangeProcessing parameter added to the File method in version 2.1. For now, you need to set a switch. You can do this one of two ways:

In runtimeconfig.json :

{
  // Set the switch here to affect .NET Core apps
  "configProperties": {
    "Switch.Microsoft.AspNetCore.Mvc.EnableRangeProcessing": "true"
  }
}

or:

 //Enable 206 Partial Content responses to enable Video Seeking from 
 //api/videos/{id}/file,
 //as per, https://github.com/aspnet/Mvc/pull/6895#issuecomment-356477675.
 //Should be able to remove this switch and use the enableRangeProcessing 
 //overload of File once 
 // ASP.NET Core 2.1 released

   AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Mvc.EnableRangeProcessing", 
   true);

See ASP.NET Core GitHub Repo for details.


My answer is based on Yuli Bonner, but with the adaptations so that it answers the question directly, and with Core 2.2

 public IActionResult GetFileDirect(string f)
{
   var path = Path.Combine(Defaults.StorageLocation, f);
   var res = File(System.IO.File.OpenRead(path), "video/mp4");
   res.EnableRangeProcessing = true;
   return res;
} 

This allowed for seeking in the browser.