gcs.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:dancedeets-monorepo 作者: mikelambert 项目源码 文件源码
def get_object(bucket, filename):
    if test_mode:
        return 'Dummy Object'

    try:
        service = _create_service()

        # Use get_media instead of get to get the actual contents of the object.
        # http://g.co/dv/resources/api-libraries/documentation/storage/v1/python/latest/storage_v1.objects.html#get_media
        req = service.objects().get_media(bucket=bucket, object=filename)

        out_file = io.BytesIO()
        downloader = http.MediaIoBaseDownload(out_file, req)

        done = False
        while done is False:
            status, done = downloader.next_chunk()
            logging.info("Download {}%.".format(int(status.progress() * 100)))

        return out_file.getvalue()
    except errors.HttpError as e:
        if e.resp.status == 404:
            raise NotFoundError()
        raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号