From 9559a0fd35bf0c95757a1ecadebf6418a6536515 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 14 Dec 2020 16:40:08 +0200 Subject: [PATCH] Chunk download: use the new sendfile to serve files. --- django_etebase/views.py | 11 ++--------- etebase_server/settings.py | 4 ++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/django_etebase/views.py b/django_etebase/views.py index 44c3383..1de5ed7 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -36,6 +36,7 @@ import nacl.signing import nacl.secret import nacl.hash +from .sendfile import sendfile from .token_auth.models import AuthToken from .drf_msgpack.parsers import MessagePackParser @@ -456,19 +457,11 @@ class CollectionItemChunkViewSet(viewsets.ViewSet): @action_decorator(detail=True, methods=["GET"]) def download(self, request, collection_uid=None, collection_item_uid=None, uid=None, *args, **kwargs): - import os - from django.views.static import serve - col = get_object_or_404(self.get_collection_queryset(), uid=collection_uid) - # IGNORED FOR NOW: col_it = get_object_or_404(col.items, uid=collection_item_uid) chunk = get_object_or_404(col.chunks, uid=uid) filename = chunk.chunkFile.path - dirname = os.path.dirname(filename) - basename = os.path.basename(filename) - - # FIXME: DO NOT USE! Use django-send file or etc instead. - return serve(request, basename, dirname) + return sendfile(request, filename) class CollectionMemberViewSet(BaseViewSet): diff --git a/etebase_server/settings.py b/etebase_server/settings.py index 0e78c9b..325dca9 100644 --- a/etebase_server/settings.py +++ b/etebase_server/settings.py @@ -173,6 +173,10 @@ ETEBASE_API_AUTHENTICATORS = ( ) ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked" +# Efficient file streaming (for large files) +SENDFILE_BACKEND = "django_etebase.sendfile.backends.simple" +SENDFILE_ROOT = MEDIA_URL + # Make an `etebase_server_settings` module available to override settings. try: from etebase_server_settings import *