简体   繁体   English

使用 Python 访问 Azure Blob,而不使用 Azure 存储 Blob ZEFE90A8E604A7C86BAD8787

[英]Access Azure Blob using Python without Azure Storage Blob package

I need to upload a JSON file to Azure blob using Python, using below code:我需要使用 Python 将 JSON 文件上传到 Azure blob,使用以下代码:

from azure.storage.blob import BlobClient

blob = BlobClient(account_url=ACCOUNT_URL,
                  container_name=CONTAINER_NAME,
                  blob_name = folder1/folder2/sample.json,
                  credential=CREDENTIAL)

blob.upload_blob(json.dumps(sample_json),overwrite=True)

This code works well.这段代码运行良好。 Only problem is, the package azure.storage.blob installs chardet package which is of LGPL license and its not acceptable for my project.唯一的问题是,package azure.storage.blob 安装了chardet package,它是我的项目的 LGPL 许可证并且不可接受。 Is there any other way we can upload the data to blob on Azure without using the above mentioned package?有没有其他方法可以在不使用上述 package 的情况下将数据上传到 Azure 上的 blob?

SDKs are simply a wrapper over Azure Storage REST API . SDK 只是Azure Storage REST API的包装器。 If using the SDK is not possible for you, you can write your own code that consumes REST API.如果您无法使用 SDK,您可以编写自己的代码来消耗 REST API。

For uploading blob, the REST API operation would be Put Blob : https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob .对于上传 Blob,REST API 操作将是Put Blobhttps://docs.microsoft.com/en-us/rest/api/storageservice/-blob

Considering the SDKs are open source, you can take a look at the SDK code and see how REST APIs are consumed in the SDK.考虑到 SDK 是开源的,您可以查看 SDK 代码并了解如何在 SDK 中使用 REST API。 This is where you can find the source code: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/azure/storage/blob .您可以在此处找到源代码: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/azure/storage/blob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM