首页 > 解决方案 > 如何使用 python 将原始 json 数据 [as pyhon Dictionary] 写入谷歌云存储?

问题描述

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

标签: pythonpython-3.xgoogle-cloud-storagegoogle-bucket

解决方案


For uploading data to Cloud Storage, you have only 3 methods in Python blobs object:

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

From dict, it's up to you to choose to convert it into a string and use upload_from_string method. Or you can also store it locally, in the /tmp directory (in memory file system), and then use file purpose methods.

You maybe have more capabilities with files, if you want to zip the content and/or use dedicated library that dump a dict into a file.


推荐阅读