I am using version 1.45.0 of streamlit and I have been having an intermittent problem on windows PC’s running edge and chrome where the download of a CSV is not working and instead a .htm file appears in the download manager in the browser. The mime type is correct and I have tried varous approaches including chunking the data. Sometimes it happens with a static file like a word doc but most often with the DL’ding of a csv converted from a dataframe. I dev on a mac and I never have an issue which points to a browser issue more than anything else but have not seen this before upgrading streamlit.
csv = df.to_csv(index=False).encode('utf-8')
# Create the download button
st.download_button(
label="Click to Download CSV",
data=csv,
file_name=f"{local_time.strftime('%Y%m%d_%H%M%S')}_status_report.csv",
mime="text/csv",
type="primary",
icon=":material/download:",
key="download_button",
)
Even this fails sometimes for word docs that are in a directory in my app:
def create_download_button(filename, btn_name):
"""
:param filename:
:param btn_name:
"""
file_path = get_file_path(filename) # Replace with your actual filename
if file_path.exists():
with open(file_path, 'rb') as file:
file_contents = file.read()
st.sidebar.download_button(
label=btn_name,
data=file_contents,
file_name=file_path.name,
mime='application/octet-stream' # Adjust mime type based on your file type
)
else:
st.sidebar.error("File not found")
Any Ideas? Has anyone else having this issue?
Thanks Tim