Display a 1 GB video file in react js frontend, stored in private S3 bucket using flask

ⅰ亾dé卋堺 提交于 2021-01-29 09:29:09

问题


I need to display/stream large video files in reactjs. These files are being uploaded to private s3 bucket by user using react form and flask.

I tried getObject method, but my file size is too large. get a signed url method required me to download the file.

I am new to AWS-python-react setup. What is the best/most efficient/least costly approach to display large video files in react?


回答1:


AWS offers other streaming specific services but if you really want to get them off S3 you could retrieve the files using torrent which, with the right client/videoplayer would allow you to start playing them without having to download the whole file.

Since you mentioned you're using Python, you could do this using AWS SDK like so:

import boto3

s3 = boto3.client('s3')
response = client.get_object_torrent(
    Bucket='my_bucket',
    Key='/some_prefix/my_video.mp4'
)

The response object will have this format:

{
    'Body': StreamingBody()
}

Full docs here.

Then you could use something like webtorrent to stream it on the frontend.

Two things to note about this approach (quoting docs):

  • Amazon S3 does not support the BitTorrent protocol in AWS Regions launched after May 30, 2016.
  • You can only get a torrent file for objects that are less than 5 GBs in size.


来源:https://stackoverflow.com/questions/63747857/display-a-1-gb-video-file-in-react-js-frontend-stored-in-private-s3-bucket-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!