How do you support HTTP range requests (partial content downloads) for large file streaming, enabling video seeking or resumable downloads?
Short answer
ASP.NET Core's File() result methods automatically support range requests (Range header) when the underlying stream supports seeking, returning 206 Partial Content responses for byte-range requests -- this is what enables video players to seek to arbitrary positions without…
Advertisement
AModel answer
ASP.NET Core's File() result methods automatically support range requests (Range header) when the underlying stream supports seeking, returning 206 Partial Content responses for byte-range requests -- this is what enables video players to seek to arbitrary positions without downloading the entire file, and download managers to resume interrupted downloads from a specific byte offset rather than the beginning.
[HttpGet("video/{id}")]
public async Task<IActionResult> StreamVideo(int id) {
var stream = await _storageService.OpenSeekableStreamAsync(id);
return File(stream, "video/mp4", enableRangeProcessing: true);
}
// Client requesting: Range: bytes=1000000-2000000
// Response: 206 Partial Content with just that byte rangeReal-world example
A video streaming platform enables range processing on its video download endpoint, letting users seek to any point in a video (their player requests just that byte range) without downloading the entire file up to that point first.
Likely follow-ups
- What server-side stream capabilities are required for range processing to work (seekability)?
- How do range requests interact with cloud blob storage's own native range-read support?
Related topics