Uploading a video file to an AWS S3 Bucket


I am trying to upload a video stored on a users local machine to an AWS S3 bucket using a mixture of boto3 and the st.file_uploader component however whenever I try to do this it cannot load the file.

I’ve put the code extracts below (removing security details). If anyone could help point me in the right direction I would REALLY appreciate it.

Thanks in advance!

def uploadMP4ToS3(file, bucket, s3_file):
    s3 = boto3.client('s3',
        s3.upload_file(file, bucket, s3_file)
        st.success('File Successfully Uploaded')
        return True
    except FileNotFoundError:
        st.error('File not found.')
        return False     

c1, c2 = st.columns(2)
c1.subheader("Upload MP4 Video/Audio File")
        uploaded_mp4 = c1.file_uploader("Select an MP4 file")
        if uploaded_mp4 is not None:
            if uploaded_mp4.type != "video/mp4":
                c1.error('Only MP4 videos are supported. Please upload a different file')
                c1.success(uploaded_mp4.name + ' Selected')
                bytes_data = uploaded_mp4.getvalue()
                if c1.button('Upload'):
                    with st.spinner('Uploading...'):

You might be able to use s3.upload_fileobj, which accepts a file-like object, which is what file_uploader returns. Then you can just pass the uploaded_mp4 object itself, not its name

Thank you so much, this works perfectly! Much appreciated.