Uploading a CSV file using file_uploader

Hello new user to StreamLit I am Anirudh
I am trying to read a csv file but I am always getting two main errors:
-1 unable to upload any file I want from anywhere, which was not the issue with another streamlit script within this multi-app project I made
-2 Even say I drag the file I want to upload into my streamlit project folder and use file_uploader then I am getting this issue

If i take in a text_input of the file name and the file is in my streamlit folder, then only it works! which is unfortunate because as I mentioned for this same multi-app project in another page (which is a different script) , I am able to load in a csv file from anywhere and manipulate the dataframe,

This is the traceback

File “C:\Users\ag1214\Anaconda3\lib\site-packages\streamlit\scriptrunner\script_runner.py”, line 554, in _run_script
exec(code, module.dict)File “pages\Fluke Logs.py”, line 36, in
with open(file) as f, open(“whyistemp.csv”, “w”) as out:

Attempt: I tried creating a blank whyistemp.csv and putting it in my project folder, but that isnt the issue I believe. I also added csv mlg log and txt as a type for the file_uploader, none worked
This is my code and gui

Thank you, enjoying streamlit so far.

Hi @efe_fv, welcome to the Streamlit community!

The important thing to keep in mind about st.file_uploader is that it literally uploads the bytes data via the browser. The result is you get a BytesIO buffer with the data in it, which is different than a local file reference. The examples section shows you various ways to work with the UploadedFile type:

The issue you are running into is thinking about the file belonging on your computer…that’s true when you are the developer, but what if it were someone else? There’s no way to guarantee that the user has the same file structure as you do, nor can you guarantee that the Streamlit app would have access to their filesystem.

So st.file_uploader uploads the file information through the browser and puts it inside the Streamlit app. Because the data is represented as bytes, you won’t need to use an open statement, the bytes are already in the Python variable. You just need to act upon those bytes.

Best,
Randy

1 Like

Thank you for your replyt

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