From d70beda1892e57dca6d1a74c64a01bade5c535d6 Mon Sep 17 00:00:00 2001 From: Andy Byers Date: Mon, 5 Jul 2021 13:47:44 +0100 Subject: [PATCH 1/2] Fixes save_galley for file paths. --- src/production/logic.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/production/logic.py b/src/production/logic.py index af79463524..fe0fab0a40 100755 --- a/src/production/logic.py +++ b/src/production/logic.py @@ -69,9 +69,15 @@ def save_source_file(article, request, uploaded_file): def save_galley(article, request, uploaded_file, is_galley, label=None, save_to_disk=True): - mime = files.guess_mime(uploaded_file.name) + # When save_to_disk is false the uploaded_file is a string/path. + if save_to_disk: + mime = files.guess_mime(uploaded_file.name) + else: + mime = files.file_path_mime(uploaded_file) + if mime == "application/zip": raise ZippedGalleyError("Zip galleys are not supported") + new_file = files.save_file_to_article( uploaded_file, article, From 2e4daf6dce31083d28b895061e810ec089d91879 Mon Sep 17 00:00:00 2001 From: Andy Byers Date: Wed, 28 Jul 2021 16:56:52 +0100 Subject: [PATCH 2/2] check instance of uploaded_file and handle if its a str --- src/production/logic.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/production/logic.py b/src/production/logic.py index fe0fab0a40..e23515e753 100755 --- a/src/production/logic.py +++ b/src/production/logic.py @@ -69,11 +69,10 @@ def save_source_file(article, request, uploaded_file): def save_galley(article, request, uploaded_file, is_galley, label=None, save_to_disk=True): - # When save_to_disk is false the uploaded_file is a string/path. - if save_to_disk: - mime = files.guess_mime(uploaded_file.name) - else: + if isinstance(uploaded_file, str): mime = files.file_path_mime(uploaded_file) + else: + mime = files.guess_mime(uploaded_file.name) if mime == "application/zip": raise ZippedGalleyError("Zip galleys are not supported")