i have certain functions that take only path of a file.
is there a widget that i can use to browse through my system, select a file and this widget returns the path of that file?
st.file_uploader returns the file name but not the path.
Please help
i have certain functions that take only path of a file.
is there a widget that i can use to browse through my system, select a file and this widget returns the path of that file?
st.file_uploader returns the file name but not the path.
Please help
Hey @Swaroop_Mg,
Are you looking to return the path of the file on your local machine, or the path of the file once itās uploaded via the st.file_uploader
widget?
@Caroline, thank for writing back
im looking to return the path of the file on local machine.
Hi there, I went through the same situation too. I need to pass to a function the path of a specific folder but I donāt actually need to upload any file at all.
Searching through the Streamlit blog it seems like a lot of users had the same issue, but the feature that allows to browse your local directories and choose a file/folder for retrieving the corresponding path has never been implemented
With āuploaded_file.nameā you can actually get the name of the file but not the relative path
I searched this before as well, the st.fie_uploader returns a fileIO object but not a traditional file. There is no path but only file name.
Hi @Swaroop_Mg
There are a couple of ways that you can display files or directories from which the app is running on. Here is an example of one way.
You can check out the GitHub repo of this at GitHub - sfc-gh-cnantasenamat/sandbox
Demo app at https://sandbox-app.streamlit.app/
Hope this helps!
Found a fix:
import tempfile
uploaded_file = st.file_uploader("File upload", type="pdf")
if uploaded_file:
temp_dir = tempfile.mkdtemp()
path = os.path.join(temp_dir, uploaded_file.name)
with open(path, "wb") as f:
f.write(uploaded_file.getvalue())
this will write the file that is uploaded to a temp folder and the path to the same temp folder is saved as path.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.