简体   繁体   English

有没有办法在不将 json 数据保存到本地文件的情况下将 json 文件上传到 azure blob?

[英]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参数可以是AnyStrIterableIO类型。

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.

相关问题 JSON 文件上传到 Django 不保存 - JSON file upload in Django without saving 将 pandas dataframe 上传到 azure blob 而不创建 Z628CB5675FF524F3E719BFEAAZ8 本地文件 - upload pandas dataframe to azure blob without creating csv local file 如何将.h5 文件(Keras)上传到 Azure Blob 存储而不将其保存在 Python 的磁盘中 - How to upload .h5 file(Keras) to Azure Blob Storage without saving it in disk in Python 将文件保存到 Azure Blob 存储 - Saving a file into Azure Blob storage 将文件从本地上传到 python 中的 Azure Blob 存储的问题 - Problem to upload a file from local to Azure Blob Storage in python 如何在 Python 中使用 Azure Functions 的 Azure Blob 存储绑定将 JSON 数据上传到 Azure 存储 blob - How to upload JSON data to Azure storage blob using Azure Blob storage bindings for Azure Functions in Python How can I append JSON data to an existing JSON file stored in Azure blob storage through python? - How can I append JSON data to an existing JSON file stored in Azure blob storage through python? 将数据帧保存到pyspark中本地驱动器上的JSON文件 - saving a dataframe to JSON file on local drive in pyspark 有没有办法只在azure blob存储中读取和修改.ini文件的内容,而无需使用python将其下载到本地? - Is there any way to read and modify the contents of .ini file in azure blob storage only , without downloading it in the local using python? 将 API JSON 响应直接保存到 Azure Blob 存储 json 文件 - Save API JSON Response directly to Azure Blob Storage json file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM