Allow export of binary file data

- Use io.BytesIO for non-string-data file objects
This commit is contained in:
Oliver Walters 2019-04-18 21:33:00 +10:00
parent 5d887f3785
commit 8948536f0f

View File

@ -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)