From 62d4cf88ba5cd9cae704026346838703410eb201 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 17 Dec 2021 09:21:42 +0300 Subject: [PATCH] fix upload iso method --- storages/views.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/storages/views.py b/storages/views.py index 34681bd..3828c41 100644 --- a/storages/views.py +++ b/storages/views.py @@ -91,14 +91,16 @@ def storage(request, compute_id, pool): """ def handle_uploaded_file(path, f_name): - target = os.path.normpath(os.path.join(path, f_name)) + target = os.path.normpath(os.path.join(path, str(f_name))) if not target.startswith(path): - raise Exception("Security Issues with file uploading") + raise Exception(_("Security Issues with file uploading")) - destination = open(target, "wb+") - for chunk in f_name.chunks(): - destination.write(chunk) - destination.close() + try: + with open(target, "wb+") as f: + for chunk in f_name.chunks(): + f.write(chunk) + except FileNotFoundError: + messages.error(request, _("File not found. Check the path variable and filename")) compute = get_object_or_404(Compute, pk=compute_id) meta_prealloc = False