I have a very simple streamlit app that uses Path from pathlib to display the folder name of the uploaded files. Works as expected on Firefox but not in Chrome-based browsers: I understand that might be due to some security differences between the browser but does anyone know a solution or a workaround?
Python : 3.11
Streamlit: 1.39.0
pathlib: 1.0.1
import streamlit as st
from pathlib import Path
uploaded_files = st.sidebar.file_uploader("Choose files", type="txt", accept_multiple_files=True)
if uploaded_files:
for uploaded_file in uploaded_files:
folder_name = Path(uploaded_file.name).parent.name
st.write(f"Original file name: {folder_name}")
You’re correct that it’s a security difference – the Brave behavior seems to be much more standard, and is meant to help users avoid accidentally leaking information about their computers. So, I don’t think there’s any good way to enable any behavior with the original filepath of a file that will work across browsers.
That pathlib is really obsolete, you’d better use the pathlib in the standard library.
I don’t understand why the browser would make any difference. Path(uploaded_file.name).parent.name is evaluated in the server regardless of the browser, and it should be an empty string, because it is the current directoy. That is what I get using firefox, edge and gnome web.
Try st.write(Path(uploaded_file.name).parent.resolve())to check. Anyway that is not “the folder name of the uploaded files”. That information is not available to your application.
Thanks for the reply.
I’m not entirely sure I understand what you mean.
What you suggested: st.write(Path(uploaded_file.name).parent.resolve()) returns the full path on Firefox and the the full path but the folder name on Brave/Chrome.
What do you mean exactly by “the folder name of the uploaded files”? When I drag and drop the folder on Firefox, I definitely get the folder name of the uploaded files.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.