Can we set a path for the file will be uploaded in st.fileupload API?

streamlit. file_uploaderlabeltype = Noneaccept_multiple_files = Falsekey = None
we can not find the file path, I tried, the uploaded file is not on server.
so where the file is save, can we set a path for the file will be uploaded?
Thank you.

Hey @BeyondMyself,

Are you talking about a local streamlit app or are you trying to deploy your app somewhere?

if locally:
File uploader has worked for me when I have the file in the same directory as my streamlit_app.py file

if your trying to deploy:
can you send a link to your github with the code?

Cheers,
Marisa

Code is like this:
import streamlit as st
uploaded_files = st.file_uploader(“Choose a CSV file”, accept_multiple_files=True)
for uploaded_file in uploaded_files:
bytes_data = uploaded_file.read()
st.write(“filename:”, uploaded_file.name)
st.write(bytes_data)

The code locates at path: C:\ on server machine
I tried open the browser of server machine and my computer.
The result is same, the file name can be seen on web browser, but where the path of file can not found, even the path of C:\ on server machine.

My purpose is open the browser on my computer to upload the file, and the file can be transfer to the server machine, if we can set the path of file on the server machine will be best.

Can we achive it now?

Hey @BeyondMyself,

Sorry I have been a bit slow to get back to you!

So!! st.file_uploader it actually does not save anything to your local (or server) machine! The file you upload is floating in memory (RAM).

If you would like to upload a file using the uploader and then save a copy to your machine (can you tell me why/use case your using here?) you will need to save that file yourself, using pickle or another package that has the ability to save files to disk.

Pickle docs are here if you want to check them out

Happy Streamlit-ing!
Marisa

If the st.file_uploader can not save anything to local or server machine, what is its designed function?
The reason why I want to use st.file_uploader is I found it was simple and in some cases, we need upload file to server machine to complete file upload. The uploaded file can be shared among different website user.
I do not think it is a singe and small case, upload component need is very common on most website.
If our st.file_uploader component can achive this goal, it will be more popular among streamlit developers.
Can ypu push this component achieve its true upload function?
Thank you.

Hey @BeyondMyself,

Excellent Question! :sparkles: So the file uploader was designed for processing files directly in your app while it is running, not for storing files or as a short cut into your server.

If your interested in more details read this section

Streamlit in general provides a webapp but does not provide a server interface. Part of this is due to security concerns, as you would not want anyone to just be able to upload any file as it could turn out to be malware and wipe your system or worse!! :grimacing:

Another factor, is memory usage. For example, file uploader does not preserve files and because of that we can clean up after ourselves. But, if we were to make a file permanent then it’s a possibility that your memory allocation can be filled rapidly and increase your costs to run the server!

From your message it sounds like your using this for more of a business option (website), and I wonder if our Streamlit for Teams might have more of the functionality that you want/need!? It’s not out yet (its scheduled to launch this year), but if your interested you can sign up for email updates here: https://www.streamlit.io/for-teams

A second option, if you’re looking for this feature right away is to design a component for it. Components are features that users have developed that anyone can pip install and use with Streamlit! Here is a link to our components page if that interests you: https://www.streamlit.io/components

A third option (sorry this post turned out so long, I just want to make sure you know all possible routes you can take! :rofl:) is on github we have a place where you can request features, here is the link for you!
https://github.com/streamlit/streamlit/issues

Happy Streamlit-ing!
Marisa

2 Likes

Thank you. I used the st.fileuplader component in data analysis, it is very convenient.
If we can add upload function to server’s specific path, and set a switch of true or false(true means upload to server, false means save in RAM), this component will be better in future.