【问题标题】:how to upload a video to google cloud storage in python如何在 python 中将视频上传到谷歌云存储
【发布时间】:2018-05-15 12:23:11
【问题描述】:

我使用了一个 AppEngine 应用程序并将我的所有文件存储在云存储中。

我也尝试存储视频,但我不能。

我不明白可恢复上传的工作原理和设置方法。

【问题讨论】:

    标签: python google-app-engine google-cloud-storage


    【解决方案1】:

    这样的事情应该可以工作:

    import cloudstorage as gcs
    
    DEFAULT_GCS_BUCKET = {your bucket}
    id ={some id}
    
    video = request.files['video']
    
    # to see what these do: https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/retryparams_class
    write_retry_params = gcs.RetryParams(   initial_delay =     0.2,
                                                backoff_factor =    2,
                                                max_delay =         5.0,
                                                min_retries =       1,
                                                max_retries =       3,
                                                max_retry_period =  15,
                                                urlfetch_timeout =  10
                                            )
    
    
    video_bytes = video.read()
    content_type = video.content_type
    
    with gcs.open(
            filename =      '{}/{}'.format(DEFAULT_GCS_BUCKET', id), 
            mode =          'w', 
            content_type =  content_type, 
            options=        {  
                                'x-goog-acl': 'public-read', 
                                'Cache-Control': 'private, max-age=0, no-transform'
                            },
            retry_params =  write_retry_params
        ) as f:
        f.write(video_bytes)
    

    【讨论】:

      猜你喜欢
      • 2019-12-10
      • 2021-06-09
      • 2017-12-04
      • 1970-01-01
      • 2017-12-06
      • 2020-08-26
      • 1970-01-01
      • 2020-03-19
      • 2018-10-02
      相关资源
      最近更新 更多