From 19662d8329c622f7600eee982313dee52703c479 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Apr 2016 09:26:25 +0100 Subject: [PATCH] Fix bug with large file uploads Depending on the size of the uploaded file, Flask will temporarily store it in different ways. This means that it comes back as a `TempFile` if the file is roughly <500k and as `BytesIO` if the file is larger. `TempFile` supports the `.getvalue()` method, but `BytesIO` does not. Both support the `.read()` method, so this commit changes to use that instead. --- app/main/views/send.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index 6773dca08..89d10c5f8 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -110,7 +110,7 @@ def send_messages(service_id, template_id): service_id, { 'file_name': form.file.data.filename, - 'data': form.file.data.getvalue().decode('utf-8') + 'data': form.file.data.read().decode('utf-8') }, current_app.config['AWS_REGION'] )