✅ Memory issue in ASP.NET Core video playback endpoint

[HttpGet("filePreview")]
public async Task<IActionResult> GetFileForPreview(string filePath)
{
    if (!System.IO.File.Exists(filePath))
    {
        return NotFound("File not found");
    }

    var extension = Path.GetExtension(filePath).ToLowerInvariant();
    var mimeType = extension switch
    {
        ".txt" => "text/plain",
        ".jpg" or ".jpeg" => "image/jpeg",
        ".png" => "image/png",
        ".gif" => "image/gif",
        ".mp4" => "video/mp4",
        ".webm" => "video/webm",
        ".mp3" => "audio/mpeg",
        ".wav" => "audio/wav",
        ".webp" => "image/webp",
        ".pdf" => "application/pdf",
        _ => null
    };

    if (mimeType == null)
    {
        return BadRequest("Unsupported file type");
    }
    Response.Headers["X-Accel-Buffering"] = "no";
    return PhysicalFile(filePath, mimeType, enableRangeProcessing: true);
}


<video preload="auto" *ngIf="file.fileType==FileType.Video" [src]="'https://localhost:7219/api/Retrievals/filePreview?filePath='+file.filePath"  controls width="600"></video>


I'm trying to implement a very basic endpoint which responds with file to angular front-end but when video is fetched its all good even when video is playing normally and even when I seek the video forward but the second I seek the video backwards and continuously seek it back and forth the ram usage increases by MBs the more I seek and since the time I seek the video back the ram usage keeps rising in 1 MBs or so every few seconds even as video is playing normally which didn't happen until i seek the video back.

I'm talking about a 450 MB 3-4 mins video.

The ram usage never goes down either, why's this happening, should I be concerned or will GC do its thing eventually or as memory rises more?
Was this page helpful?