diff --git a/links/file_views.py b/links/file_views.py index 877e54a..c2f3d5b 100644 --- a/links/file_views.py +++ b/links/file_views.py @@ -7,7 +7,7 @@ from pathlib import Path from django.conf import settings from django.db.models import F -from django.http import FileResponse, JsonResponse, Http404 +from django.http import FileResponse, JsonResponse, Http404, HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.utils.dateparse import parse_datetime from django.views import View @@ -47,6 +47,74 @@ def _save_uploaded_file(f): ) +def _stream_file(file_path, mime_type, disposition, range_header=None): + """Return a streaming response for a media file that honours HTTP Range. + + Browsers send a ``Range: bytes=start-end`` header to seek inside + ``