Skip to content

Commit 601c285

Browse files
coenvdgrintenknokko
authored andcommitted
Check for video content and set headers
1 parent e011ab2 commit 601c285

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

binder/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,9 @@ def dispatch_file_field(self, request, pk=None, file_field=None):
29032903
guess = mimetypes.guess_type(file_field.name)
29042904
content_type = (guess and guess[0]) or 'application/octet-stream'
29052905
serve_directly = isinstance(field, BinderFileField) and field.serve_directly
2906+
2907+
is_video = content_type and content_type.startswith('video/')
2908+
29062909
try:
29072910
if serve_directly:
29082911
resp = HttpResponse(content_type=content_type)
@@ -2912,7 +2915,10 @@ def dispatch_file_field(self, request, pk=None, file_field=None):
29122915
if not file_field.url.startswith('/'):
29132916
resp['redirect_url'] = file_field.url
29142917
else:
2915-
resp = FileResponse(file_field.open(), content_type=content_type)
2918+
file_handle = file_field.open('rb')
2919+
resp = FileResponse(file_handle, content_type=content_type)
2920+
if is_video:
2921+
resp['Accept-Ranges'] = 'bytes'
29162922
except FileNotFoundError:
29172923
logger.error('Expected file {} not found'.format(file_field.name))
29182924
raise BinderNotFound(file_field_name)

0 commit comments

Comments
 (0)