curl --request GET \
--url https://api.example.com/api/stream/{filename}{
"404": {},
"Content-Type": "<string>",
"Content-Length": 123,
"Content-Range": "<string>",
"Accept-Ranges": "<string>"
}Stream downloaded video files with HTTP range request support for efficient video playback
curl --request GET \
--url https://api.example.com/api/stream/{filename}{
"404": {},
"Content-Type": "<string>",
"Content-Length": 123,
"Content-Range": "<string>",
"Accept-Ranges": "<string>"
}Range header, which allows clients to request specific portions of a file. This is essential for:
Range: bytes=start-end headertitle__task-id.ext).bytes=start-endstart: Zero-based byte offset (required)end: Last byte to include (optional, defaults to end of file)bytes=0-1023 - First 1024 bytesbytes=1024- - From byte 1024 to end of filebytes=1000-2000 - Bytes 1000 through 2000 inclusivevideo/mp4bytes start-end/totalExample: bytes 0-1023/5242880 (first 1024 bytes of a ~5MB file)bytes to indicate the server supports range requestsvideo/mp4bytes=(\d+)-(\d*)
file_size - 1 to prevent out-of-bounds readsdef iterfile():
with open(filepath, "rb") as f:
f.seek(start)
remaining = chunk_size
while remaining > 0:
data = f.read(min(65536, remaining))
if not data:
break
remaining -= len(data)
yield data
curl http://localhost:8001/api/stream/My_Video__123e4567-e89b-12d3.mp4
curl -H "Range: bytes=0-1048575" \
http://localhost:8001/api/stream/My_Video__123e4567-e89b-12d3.mp4
HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1048575/52428800
Accept-Ranges: bytes
Content-Length: 1048576
Content-Type: video/mp4
[binary data...]
curl -H "Range: bytes=10485760-" \
http://localhost:8001/api/stream/My_Video__123e4567-e89b-12d3.mp4
HTTP/1.1 206 Partial Content
Content-Range: bytes 10485760-52428799/52428800
Accept-Ranges: bytes
Content-Length: 41943040
Content-Type: video/mp4
[binary data...]
# Request bytes from ~25MB mark
curl -H "Range: bytes=26214400-27262975" \
http://localhost:8001/api/stream/My_Video__123e4567-e89b-12d3.mp4
HTTP/1.1 206 Partial Content
Content-Range: bytes 26214400-27262975/52428800
Accept-Ranges: bytes
Content-Length: 1048576
Content-Type: video/mp4
[binary data...]
<video controls width="640">
<source src="http://localhost:8001/api/stream/My_Video__123e4567-e89b-12d3.mp4"
type="video/mp4">
</video>
{
"detail": "Archivo no encontrado"
}
<video> tag: Sends range requests when seeking