Get path from file_uploader()

Other than uploading to cloud, there is also the very useful tempfile module including the NamedTemporaryFileclass.

Something along the lines of:

from tempfile import NamedTemporaryFile
import streamlit as st

uploaded_file = st.file_uploader("File upload", type='csv')
with NamedTemporaryFile(dir='.', suffix='.csv') as f:
    f.write(uploaded_file.getbuffer())
    your_function_which_takes_a_path(f.name)

Should work.

9 Likes