我目前正在尝试使用Python API从Google Storage
下载一些文件。显然,这可以通过使用gsutil's cp来完成,事实上我可以做到。
sudo gsutil cp gs://???/stats/installs/*.csv .
但是,我发现Google Python API
的所有示例都没有涵盖这个主题,我甚至在考虑API是否涵盖了此功能。
答案 0 :(得分:4)
此 涵盖Python Example | Cloud Storage Documentation | Google Cloud Platform(谷歌中的第一个“google storage python wrapper”):
下载对象:
storage/api/crud_object.py
(View on GitHub)def get_object(bucket, filename, out_file): 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) downloader = http.MediaIoBaseDownload(out_file, req) done = False while done is False: status, done = downloader.next_chunk() print("Download {}%.".format(int(status.progress() * 100))) return out_file