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
评论列表
文章目录