Measure upload speed when using st.file_uploader

I’d like to measure the upload speed when using the st.file_uploader component

with st.form("my-form", clear_on_submit=True):

        print(f"pre upload: {time.time() - startuptime:0.1f}")
        uploaded_files = st.file_uploader(
            label="Import data",
            type=[".zip", ".7z", ".pcd", ".xml", ".jpg"],
        submitted = st.form_submit_button("UPLOAD!")

I.e. the time it takes for data to “travel” from the client’s browser until it’s available in the backend. Reason: I’m inside a corporate network that has vastly different speeds depending on client’s location.
I’m able to grab the timestamp when the data is available, but I didn’t manage to get the timestamp when the upload is initiated.

Is this possible? If yes how would I do this?

best regards,

Hi @Dominic_Mai,

Thanks for sharing this question!

This might be a bit tricky to accomplish without using some JavaScript code on the client side. Streamlit API doesn’t directly expose events or hooks you can use to capture the start time for uploads.

Hi @tonykip,

thx for the quick answer! Then I’ll probably figure out the speed outside of streamlit.

best regards,

Great. If you end up with a working solution, please post it here so other can benefit from it as well.