【问题标题】:Download blob object as a string instead of saving it as a file and then read it将 blob 对象下载为字符串,而不是将其保存为文件然后读取它
【发布时间】:2021-05-23 02:47:43
【问题描述】:

假设我在 Google 有一个存储空间,其中包含 blob_file

{"name":"my name",
"number:"my number"
}

有没有办法下载这个文件并将下载作为纯字符串返回,而不是将其保存为文件,例如

import json
from google.cloud import storage

downloaded_json = storage.blob.some_function(bucket_name="mybucket",blob_file="blob_file") #Gets the context of "blob_file" as a string

print(downloaded_json)
#'{"name":"my name",
#"number:"my number"
#}'
name_dict = json.loads("downloaded_json") #Convert it to a dictionary such that it can be used

print(name_dict["name"])
#"my name"

我知道我可以下载文件、读取文件、删除文件 - 但这是为了避免这种情况,看起来你可以在 Java 中这样做

【问题讨论】:

    标签: python-3.x google-cloud-platform google-cloud-storage blobstore


    【解决方案1】:

    您可以使用在 Google Cloud Storage 客户端库 here 中记录的 download_as_text 函数

    【讨论】:

      猜你喜欢
      • 2020-02-28
      • 2018-06-11
      • 2019-03-29
      • 1970-01-01
      • 2020-02-19
      • 2019-04-11
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      相关资源
      最近更新 更多