Issues/question regaring st.file_uploader

Hello,

This might be a stupid question but Im new to python and new to streamlit.

Trying to make an app that would let the user select a local .tgz archive using the st.file_uploader. The file changes from use to use but the content will keep a strict format - I want the app to parse and display the information.

The 2nd-part I’ve figured out using pandas - my issue is with streamlit and the st.file_uploader - How do I interact with the object that is uploaded in a correct way - the object will as I said always be a .tgz archive with strict formatting.

The code looks like this at the moment - trying to extract the tgz using tarfile.

with sidebar:
    st.sidebar.title("Selection:")

    st.sidebar.subheader("Select a .tgz ")
    file = st.sidebar.file_uploader("Fileselector", type="tgz")

    if not file == None:
        st.sidebar.write(file)
        tar = tarfile.open(file)
        tar.extractall()
        st.write(tar)
    else:
        st.sidebar.write("No file selected")

Getting stuck with this error:
“TypeError: expected str, bytes or os.PathLike object, not UploadedFile”

Any ideas?

Thanks in advance.

Hi @Petter, welcome to the Streamlit community!

Please see the documentation for st.file_uploader here, specifically the examples section:

https://docs.streamlit.io/library/api-reference/widgets/st.file_uploader

I would guess that tarfile.open(file) does not know what you mean, but if you did tarfile.open(file.getvalue()) would, as you’d be passing a BytesIO buffer to the open function.

Best,
Randy

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.