locked
PhysicalFile not returning response for range requests RRS feed

  • Question

  • User-1738839812 posted

    Hey,

    I have a problem delivering videos in .NET Core. I'm getting a video file by an absolute path and returning it to be used as a source in a <video> element. However, I'm enabling HTTP Range requests by passing enableRangeProcessing: true to the method, and after fast seeking through the video (once it's loaded) the action stops providing responses. The response contains exactly 16.1kb of data and does not contain any response preview or response content at all. Reloading the page after that does not help, the only thing that fixes it is rebuild and rerun again, or sometimes if you wait a while (2-3 minutes) the video loads normally on reload. Does anyone know what might be causing this?

    The action in question

    public IActionResult GetVideo(string path) {
        path = Uri.UnescapeDataString(path);
        return PhysicalFile(path, "application/octet-stream", enableRangeProcessing: true);
    }

    And here's the front-end side

    <video src="@Url.Action("GetVideo", "Home", new { path = ViewBag.Id })" controls></video>

    The path variable is an URI-escaped string of the absolute path in my system (for debugging purposes, it will be through IDs in the future.

    Tuesday, March 3, 2020 1:41 PM

All replies

  • User-854763662 posted

    Hi Emberfire,

    I tested your code and it worked well , the below is a working demo which gets more than 20 megabits of video in asp.net  core 3.0:

    Controller:

    public IActionResult Privacy()
    {
          ViewBag.Id = @"C:\Vediotest\movie-4.mp4";
    
          return View();
    }
    
    public IActionResult GetVideo(string path)
    {
           path = Uri.UnescapeDataString(path);
           return PhysicalFile(path, "application/octet-stream", enableRangeProcessing: true);
    }

    View

    @{
        ViewData["Title"] = "Privacy Policy";
    }
    <h1>@ViewData["Title"]</h1>
    
    <p>Use this page to detail your site's privacy policy.</p>
    
    
    <video src="@Url.Action("GetVideo", "Home", new { path = ViewBag.Id })" controls></video>

    If the Accept-Ranges is present in HTTP responses (and its value isn't "none"), the server supports range requests.

    If you want the community review and debug the code , could you share a complete demo link that can reproduce the issue?

    Best Regards,

    Sherry

    Wednesday, March 4, 2020 3:37 AM
  • User-1738839812 posted

    Hey there Sherry,

    Thank you for replying, and I'm sorry for the late reply, just now saw your comment.

    About the issue, yes, initially it loads normally, however my problem is more with multiple requests in quick succession. I can't provide accurate reproduction steps because the bug appears to happen inconsistently (or so it seems) but more often than not it happens when you load a video initially (preferably a longer one, the videos i'm trying to display are actually movies from my PC) and then try to "seek" through the video in quick succession. I'm seeing about 100-150 requests in DevTools (most of them cancelled, but still). After that, the requests stop responding with parts of the movie. Again, this does not happen every time and sometimes the issue disappears after 2-3 minutes. Here's a video capturing the issue. As described above, about 3 minutes after I stopped recording the video loaded normally.

    Thanks again :)

    Thursday, March 5, 2020 7:06 PM