我目前正在尝试使用 Python API 从 Google Storage
下载一些文件。显然这可以通过使用 gsutil's cp 来完成,我确实能做到。
sudo gsutil cp gs://???/stats/installs/*.csv 。
但是,我发现的所有 Google Python API
示例均未涵盖此主题,我什至正在考虑 API 是否涵盖此功能。
最佳答案
此由 Python Example | Cloud Storage Documentation | Google Cloud Platform 涵盖(Google 中关于“Google Storage Python 包装器”的第 1 个):
To download an object:
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
关于python - 如何通过 python 以编程方式从 Google Storage 下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40510782/