I have an app that allows to edit an uploaded Word document. The edits would need to be saved as a separate document and then saved. To accomplish this I use the st.download_button. However, when I run the code I get this error: RuntimeError: Invalid binary data format: <class ‘NoneType’>. And this one as well: RuntimeError(“Invalid binary data format: %s” % type(data)).
Why do these errors occur? Any form of help would be appreciated.
I am using Python 3.10.4, Streamlit 1.11.1, Virtualenv, PyCharm Community Edition 2022.1.4, Windows 11, Firefox 103.0.1 (64-bit).
Python-docx’s method accepts a stream instead of a filename. Thus, you can initialize an io.BytesIO() object to save the document into, then dump that to the user.
I have tried this and it worked for me
doc_download = doc_file_creation(doc_file)
bio = io.BytesIO()
label="Click here to download",