[英]Is there a way to upload a json file to an azure blob without saving the json data to a local file?
I am making a python based webapp that uses jsons to store information for different accounts.我正在制作一个基于 python 的 webapp,它使用 jsons 来存储不同帐户的信息。 I am not able to temporarily save the json data to a local file and then upload it to a blob.我无法将 json 数据临时保存到本地文件,然后将其上传到 blob。 Is there a way to remove that step and just upload the json data directley as a file in a blob?有没有办法删除该步骤,只需将 json 数据直接上传为 blob 中的文件?
This is how you normally upload a file这是您通常上传文件的方式
with open(upload_file_path, "rb") as data:
blob_client.upload_blob(data)
Is there something like blob_client.upload_blob(<json object>)
that works?有类似blob_client.upload_blob(<json object>)
的东西吗?
Is there something like blob_client.upload_blob(<json object>) that works?有类似 blob_client.upload_blob(<json object>) 的东西吗?
Yes.是的。 If you look at the documentation for upload_blob
, you will notice that the data
parameter can be of AnyStr
, Iterable
or IO
type.如果查看upload_blob
的文档,您会注意到data
参数可以是AnyStr
、 Iterable
或IO
类型。
What you could do is serialize the JSON object as string using json.dumps()
and pass that as data to the upload_blob method.您可以做的是使用json.dumps()
将 JSON object 序列化为字符串并将其作为数据传递给 upload_blob 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.