From 8948536f0faf12d36b0da48ae5f45d00a022ebb7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 21:33:00 +1000 Subject: [PATCH] Allow export of binary file data - Use io.BytesIO for non-string-data file objects --- InvenTree/InvenTree/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index ebdb8953fa..ba3f3525d5 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -23,7 +23,10 @@ def DownloadFile(data, filename, content_type='application/text'): filename = WrapWithQuotes(filename) - wrapper = FileWrapper(io.StringIO(data)) + if type(data) == str: + wrapper = FileWrapper(io.StringIO(data)) + else: + wrapper = FileWrapper(io.BytesIO(data)) response = StreamingHttpResponse(wrapper, content_type=content_type) response['Content-Length'] = len(data)