This application is a simple demonstration of streaming binary data (e.g. Word, Excel, PowerPoint and PDF) back using Flask. There are 2 types of data being streamed back; one being the binary file itself and the other being the base64 encoded version of the binary file. For now, when the binary file is streamed back, it is chunked; however, for the base64 encoded version, there is no chunking (someone work on that and contribute) as the whole file is read and then streamed back. Chunking is important to avoid memory issues.
Build it.
./docker-local.sh
Run it.
docker run -it -p 80:80 --rm nginx-stream-binary:local
Observe it.
- http://localhost/v1/docx
- http://localhost/v1/pptx
- http://localhost/v1/xlsx
- http://localhost/v1/pdf
- http://localhost/v1/b64/docx
- http://localhost/v1/b64/pptx
- http://localhost/v1/b64/xlsx
- http://localhost/v1/b64/pdf
- Reading a binary file with Python
- Flask make response with large files
- Flask streaming
- Office 2007 file format mime types for http content streaming
- Flask Headers
- Flask Response Objects
- Extrating extension from file in Python
- Unknown file type MIME
- Get the current time in milliseconds in Python
- Encoding image file with base64
- Convert bytes to string
- Writing and reading chunked base64
Check out Martin Fowler. He's my among my favorite coding gurus.
@misc{oneoffcoder_nginx_stream_binary_2019,
title={HOWTO stream binary files with Flask},
url={https://github.com/oneoffcoder/docker-containers/tree/master/nginx-stream-binary},
journal={GitHub},
author={One-Off Coder},
year={2019},
month={Jun}}