Use StreamingHttpResponse when downloading zip streams

pull/1527/head
Piero Toffanin 2024-07-18 15:11:25 -04:00
rodzic a0e1acd196
commit 4669adf495
3 zmienionych plików z 18 dodań i 8 usunięć

Wyświetl plik

@ -11,6 +11,8 @@ from django.core.files.uploadedfile import InMemoryUploadedFile
from django.db import transaction
from django.http import FileResponse
from django.http import HttpResponse
from django.http import StreamingHttpResponse
from app.vendor import zipfly
from rest_framework import status, serializers, viewsets, filters, exceptions, permissions, parsers
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
@ -340,8 +342,13 @@ def download_file_response(request, filePath, content_disposition, download_file
def download_file_stream(request, stream, content_disposition, download_filename=None):
response = HttpResponse(FileWrapper(stream),
content_type=(mimetypes.guess_type(download_filename)[0] or "application/zip"))
if isinstance(stream, zipfly.ZipStream):
f = stream.generator()
else:
# This should never happen, but just in case..
raise exceptions.ValidationError("stream not a zipstream instance")
response = StreamingHttpResponse(f, content_type=(mimetypes.guess_type(download_filename)[0] or "application/zip"))
response['Content-Type'] = mimetypes.guess_type(download_filename)[0] or "application/zip"
response['Content-Disposition'] = "{}; filename={}".format(content_disposition, download_filename)

13
app/vendor/zipfly.py vendored
Wyświetl plik

@ -46,7 +46,6 @@ class ZipflyStream(io.RawIOBase):
def size(self):
return self._size
class ZipFly:
def __init__(self,
@ -280,13 +279,17 @@ class ZipFly:
class ZipStream:
def __init__(self, paths):
self.paths = paths
self.generator = None
self._generator = None
def lazy_load(self, chunksize):
if self.generator is None:
if self._generator is None:
zfly = ZipFly(paths=self.paths, mode='w', chunksize=chunksize)
self.generator = zfly.generator()
self._generator = zfly.generator()
def read(self, count):
self.lazy_load(count)
return next(self.generator)
return next(self._generator)
def generator(self):
self.lazy_load(0x8000)
return self._generator

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "WebODM",
"version": "2.5.3",
"version": "2.5.4",
"description": "User-friendly, extendable application and API for processing aerial imagery.",
"main": "index.js",
"scripts": {