Creating Download Button

Hi, @arwa there is a hack you can use to download a file from streamlit

import os
import base64
import streamlit as st

st.title('Downloader')

def get_binary_file_downloader_html(bin_file, file_label='File'):
    with open(bin_file, 'rb') as f:
        data = f.read()
    bin_str = base64.b64encode(data).decode()
    href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(bin_file)}">Download {file_label}</a>'
    return href

st.markdown(get_binary_file_downloader_html('info.txt', 'Text Download'), unsafe_allow_html=True)

Hope this is helpful.

1 Like