Path to file

Hello. I use st.file_uploader( for upload video-file. I get video - st.file_uploader(label, type=‘mp4’ ). Then i can to play video. But i use the function , it need path to video-file. I can use path only from github. But users cant to upload file to github. Do you know how to get some path to file?

Which function? st.video doesn’t need a path.

data = st.file_uploader(label="Upload file", type="mp4")
st.video(data, format="video/mp4")

It YoloTracking. Neural network. It need a path to video. I can`t to change it.

Store the data in a temporary file and pass the file name to your video function. I don’t know if flushing is necessary but better safe than sorry.

import tempfile
import streamlit as st


def video_function(path):
    st.video(path, format="video/mp4")


data = st.file_uploader(label="Upload file", type="mp4")

with tempfile.NamedTemporaryFile() as f:
    f.write(data.read())
    f.flush()
    video_function(f.name)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.