From 70e091e2133fe72b17086269f06cfcdf234ab2c2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Makodin Date: Thu, 7 May 2026 05:37:02 +0500 Subject: [PATCH] fix: read file content into memory before closing file handle in download view (#247) --- rdgenerator/views.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rdgenerator/views.py b/rdgenerator/views.py index 51612f8..e8e20d4 100644 --- a/rdgenerator/views.py +++ b/rdgenerator/views.py @@ -395,14 +395,13 @@ def check_for_file(request): def download(request): filename = request.GET['filename'] uuid = request.GET['uuid'] - #filename = filename+".exe" - file_path = os.path.join('exe',uuid,filename) + file_path = os.path.join('exe', uuid, filename) with open(file_path, 'rb') as file: - response = HttpResponse(file, headers={ - 'Content-Type': 'application/vnd.microsoft.portable-executable', - 'Content-Disposition': f'attachment; filename="{filename}"' - }) - + content = file.read() + response = HttpResponse(content, headers={ + 'Content-Type': 'application/vnd.microsoft.portable-executable', + 'Content-Disposition': f'attachment; filename="{filename}"' + }) return response def get_png(request):