From 83ce862a834f1659f73fd65f635c103969c5a3b8 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Wed, 13 Aug 2025 20:43:28 +0300 Subject: [PATCH] Features:; Fixes:; Extra: 1) Simplify `FileResponse` usage and reduce redundant code in file download logic;. --- core/views.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/views.py b/core/views.py index c9d5c9fd..a3b28f30 100644 --- a/core/views.py +++ b/core/views.py @@ -488,11 +488,10 @@ def download_digital_asset_view(request, *args, **kwargs): if not content_type: content_type = "application/octet-stream" - with open(file_path, "rb") as file: - response = FileResponse(file, content_type=content_type) - filename = os.path.basename(file_path) - response["Content-Disposition"] = f'attachment; filename="{filename}"' - return response + response = FileResponse(open(file_path, "rb"), content_type=content_type) + filename = os.path.basename(file_path) + response["Content-Disposition"] = f'attachment; filename="{filename}"' + return response except BadRequest as e: return JsonResponse(camelize({"error": str(e)}), status=400)