在我的开发服务器中,我可以使用blobkey来下载csv对象。问题是在生产中,blobkey不会下载任何东西(它返回404);大概是因为blobkey不准确。我认为这是因为谷歌不再支持blobstore,不再使用blobkey。这意味着我需要尝试从google存储桶中下载。我不确定如何做到这一点;在开发服务器中,我将转到此端点下载/data?key=<blob_key>以下载blob对象。
如果我导航到存储桶并打开项目,然后单击download,我也可以下载csv对象。我可以做一些小的调整来让下载发生吗?如果有人能给我指个特别的方向,我将不胜感激。
发布于 2020-02-19 17:28:00
要根据您的偏好从云存储的存储桶中下载对象,您可以查看以下代码示例(Python):
from google.cloud import storage
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
# bucket_name = "your-bucket-name"
# source_blob_name = "storage-object-name"
# destination_file_name = "local/path/to/file"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print(
"Blob {} downloaded to {}.".format(
source_blob_name, destination_file_name
)
)请确保您不再使用Python 2.7,因为它已被弃用,并且不再受支持。如果你有Python 2.7,请升级到Python 3.7。
https://stackoverflow.com/questions/60287648
复制相似问题