Inconsistent folder name across browsers

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}")

Firefox:

Brave:

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.

Oh, wait. You are uploading folders. I totally misunderstood the issue. Sorry about that.