如何使用Boto3烧瓶将本地视频上传到AWS S3

我是新来的烧瓶。 我想使用flask在s3 aws中上传视频。此外,每次上传新文件时,文件名都会更改。 并且存储桶中有子文件夹,例如我要在视频中上传的存储桶名称/视频

def uploadvideo():
finalResult = 'abc.mp4'
s3_bucket_video_url = 'media-storage-beta' + '/videos/' + 'video'
s3 = boto3.client('s3')
response = s3.upload_file(
    finalResult,'media-storage-beta','video')
return 'success'
iCMS 回答:如何使用Boto3烧瓶将本地视频上传到AWS S3

您需要在virtualenv中安装boto3。还取决于您在哪里运行Flask应用。如果您尝试从本地上传。您需要在ENV变量中使用AWS访问密钥。您可以在flask中定义这样的路由。此处使用带有视频标题和上载文件格式的表单。

@app.route('/uploadvideo',methods=['POST'])
def uploadvideo():
    if request.method == 'POST':
        print(request.form['videotitle'])
        f_video = request.files['videofile']
        print(f_video.filename)
        # create video_url
        s3_bucket_video_url = <Main_Folder> + '/videos/' + video_file_name
        s3_client = boto3.client('s3')
        response = s3_client.upload_file(
            f.filename,<BUCKET_NAME>,s3_bucket_video_url)
        return 'Success'

谢谢

Ashish

本文链接:https://www.f2er.com/1989517.html

大家都在问