mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Use file.chunks() on large cached files
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
from django.http import FileResponse, Http404, HttpRequest, HttpResponse
|
from django.http import Http404, HttpRequest, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from pretix.base.models import CachedFile
|
from pretix.base.models import CachedFile
|
||||||
|
from pretix.helpers.http import ChunkBasedFileResponse
|
||||||
|
|
||||||
|
|
||||||
class DownloadView(TemplateView):
|
class DownloadView(TemplateView):
|
||||||
@@ -20,7 +21,7 @@ class DownloadView(TemplateView):
|
|||||||
if 'ajax' in request.GET:
|
if 'ajax' in request.GET:
|
||||||
return HttpResponse('1' if self.object.file else '0')
|
return HttpResponse('1' if self.object.file else '0')
|
||||||
elif self.object.file:
|
elif self.object.file:
|
||||||
resp = FileResponse(self.object.file.file, content_type=self.object.type)
|
resp = ChunkBasedFileResponse(self.object.file.file, content_type=self.object.type)
|
||||||
resp['Content-Disposition'] = 'attachment; filename="{}"'.format(self.object.filename)
|
resp['Content-Disposition'] = 'attachment; filename="{}"'.format(self.object.filename)
|
||||||
return resp
|
return resp
|
||||||
else:
|
else:
|
||||||
|
|||||||
9
src/pretix/helpers/http.py
Normal file
9
src/pretix/helpers/http.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from django.http import StreamingHttpResponse
|
||||||
|
|
||||||
|
|
||||||
|
class ChunkBasedFileResponse(StreamingHttpResponse):
|
||||||
|
block_size = 4096
|
||||||
|
|
||||||
|
def __init__(self, streaming_content=(), *args, **kwargs):
|
||||||
|
streaming_content = streaming_content.chunks(self.block_size)
|
||||||
|
super().__init__(streaming_content, *args, **kwargs)
|
||||||
Reference in New Issue
Block a user