would be interested to know myself. I could not get a download link working for something that was not an excel/text file. In my case I have a binary (midi) file and in both our cases this part
There is a good example in the download button offered as a work around. See:
The download_button() function is an extension of a workaround based on
the discussions covered in more detail at Awesome Streamlit.
Go to Gallery → Select the App Dropdown → Choose “File Download Workaround”
for more information.
When you use the code offered there. Check the last example to get this code:
--------------------------
# Select a file to download
# --------------------------
if st.checkbox('Select a file to download'):
st.write('~> Use if you want to test uploading / downloading a certain file.')
# Upload file for testing
folder_path = st.text_input('Enter directory: deafult .', '.')
filename = file_selector(folder_path=folder_path)
# Load selected file
with open(filename, 'rb') as f:
s = f.read()
download_button_str = download_button(s, filename, f'Click here to download {filename}')
st.markdown(download_button_str, unsafe_allow_html=True)
import base64
import shutil
def create_download_zip(zip_directory, zip_path, filename='foo.zip"):
"""
zip_directory (str): path to directory you want to zip
zip_path (str): where you want to save zip file
filename (str): download filename for user who download this
"""
shutil.make_archive(zip_path, 'zip', zip_directory)
with open(zip_path, 'rb') as f:
bytes = f.read()
b64 = base64.b64encode(bytes).decode()
href = f'<a href="data:file/zip;base64,{b64}" download=\'{filename}\'>\
download file \
</a>'
st.markdown(href, unsafe_allow_html=True)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.