Streaming video files in asp.net core 2

Just use the normal return PhysicalFile here:

public class HomeController : Controller
    {
        public IActionResult Download()
        {
            return PhysicalFile(@"d:\test\somemovie.mp4", "application/octet-stream");
        }

Because it supports range headers which are necessary for streaming and resuming a file download: enter image description here

Also return File, FileStreamResult and VirtualFileResult support partial range requests too. Even static files middleware supports that too.


Something is wrong. My sample doesn't support resume

    [HttpGet]
    [Route("Download2")]
    public IActionResult Download2()
    {
        return PhysicalFile(@"d:\test\somemovie.mp4", "application/octet-stream");
    }

enter image description here

and there is no accept-ranges in response headers

enter image description here

but when I use

[HttpGet]
    [Route("Download")]
    public async Task<IActionResult> Download()
    {
        var path = @"d:\test\somemovie.mp4";
        var memory = new MemoryStream();
        using (var stream = new FileStream(@"d:\test\somemovie.mp4", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 65536, FileOptions.Asynchronous | FileOptions.SequentialScan))
        {
            await stream.CopyToAsync(memory);
        }
        memory.Position = 0;
        return File(memory, "application/octet-stream", Path.GetFileName(path),true); //enableRangeProcessing = true
    }

with "enableRangeProcessing" parameter true

enter image description here

Can you provide more explanation why the case is this? And which solution I should use? I got confused.