How to allow user to download document generated by Streamlit straight from the server?

I’m trying to use create a simple link to access a PDF generated by streamlit.

st.write(f'To download the error report <a target="_blank" href="{error_report_filename}">click here</a>', unsafe_allow_html=True)

However, it seems like streamlit server return a 404 when you try to access any filetype direct from the path, like http://localhost:8051/report.pdf or http://localhost:8051/report.csv even though the files are there with proper permissions.

Is there any magic trick or server setup that would allow me to link directly to the file?

Hi @naurojr,

Maybe this will fit your use case A download button with custom CSS

It probably will, but the true question is WHY? So many lines of code for a link, it kind of takes away from the beauty of Python. Joking aside, thank you for your response. I saw that and a couple of other similar posts before. I was really trying to avoid to do that for the sake of simplicity.

I don’t see why not to allow the access to specific filetypes direct from the path. Specially if we make something explicit like unsafe_allow_html=True

Hi @naurojr, welcome to the Streamlit community!

It has been identified as an enhancement:

The reason it doesn’t work now is that the webserver behind Streamlit isn’t set up to allow this. It’s not an intentional removal of behavior, just a matter of us catching up in our backlog. In the meantime, Chad’s example does work.