【问题标题】:How to write raw json data [as pyhon Dictionary] to Google cloud storage using python?如何使用 python 将原始 json 数据 [as python Dictionary] 写入谷歌云存储?
【发布时间】:2020-10-03 08:13:16
【问题描述】:

我的用例非常简单,我从我的 REST API 中获取原始 JSON 响应并将其保存为 python 中的字典,我必须将此数据写入谷歌云存储。除了“upload_from_string”选项之外还有其他方法吗?

【问题讨论】:

    标签: python python-3.x google-cloud-storage google-bucket


    【解决方案1】:

    要上传数据到云存储,你有only 3 methods in Python blobs object

    • Blob.upload_from_file()
    • Blob.upload_from_filename()
    • Blob.upload_from_string()

    从 dict 中,您可以选择将其转换为字符串并使用upload_from_string 方法。或者你也可以将其存储在本地,在/tmp目录中(在内存文件系统中),然后使用file目的方法。

    如果您想压缩内容和/或使用将 dict 转储到文件中的专用库,您可能对文件有更多功能。

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 2017-12-04
      • 2013-06-26
      • 2013-08-19
      • 2018-07-08
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      • 2017-12-06
      相关资源
      最近更新 更多