Static file serving
Streamlit apps can host and serve small, static media files to support media embedding use cases that won't work with the normal media elements.
To enable this feature, set
enableStaticServing = true under
[server] in your config file,
or environment variable
Media stored in the folder
./static/ relative to the running app file is served at path
app/static/[filename], such as
Details on usage
- Files with the following extensions will be served normally:
".jpg", ".jpeg", ".png", ".gif". Any other file will be sent with header
Content-Type:text/plainwhich will cause browsers to render in plain text. This is included for security - other file types that need to render should be hosted outside the app.
- Streamlit also sets
X-Content-Type-Options:nosnifffor all files rendered from the static directory.
- For apps running on Streamlit Community Cloud:
- Files available in the Github repo will always be served. Any files generated while the app is running, such as based on user interaction (file upload, etc), are not guaranteed to persist across user sessions.
- Apps which store and serve many files, or large files, may run into resource limits and be shut down.
- Put an image
cat.pngin the folder
enableStaticServing = trueunder
- Any media in the
./static/folder is served at the relative URL like
# .streamlit/config.toml [server] enableStaticServing = true
# app.py import streamlit as st with st.echo(): st.title("CAT") st.markdown("[![Click me](app/static/cat.png)](https://streamlit.io)")