发布于 2019-09-06 07:30:35
这是我的示例代码,对我来说很好。
import os
from azure.storage.blob import BlockBlobService
root_path = '<your root path>'
dir_name = 'images'
path = f"{root_path}/{dir_name}"
file_names = os.listdir(path)
account_name = '<your account name>'
account_key = '<your account key>'
container_name = '<your container name, such as `test` for me>'
block_blob_service = BlockBlobService(
account_name=account_name,
account_key=account_key
)
for file_name in file_names:
blob_name = f"{dir_name}/{file_name}"
file_path = f"{path}/{file_name}"
block_blob_service.create_blob_from_path(container_name, blob_name, file_path)如下图所示,结果是来自Azure存储资源管理器的截图。

有关的API引用的详细信息,请参阅https://azure-storage.readthedocs.io/index.html。
更新:我使用的Python版本是WindowsPython3.7.4,所需的包是azure-storage==0.36.0,您可以从https://pypi.org/project/azure-storage/上找到它。
$ virtualenv test$ cd test$ Scripts\active$ pip install azure-storage然后,您可以在当前的Python虚拟环境中通过python upload_images.py运行我的示例代码。
发布于 2019-09-06 07:27:06
在你链接的文件里。
这不是BlobService,而是BlobClient。
from azure.storage.blob import BlobClient
blob = BlobClient.from_connection_string("my_connection_string", container="mycontainer", blob="my_blob")
with open("./SampleSource.txt", "rb") as data:
blob.upload_blob(data)发布于 2020-09-18 12:05:38
目前有两个版本的azure.storage.blob。如果您创建了一个Azure VM并在那里处理数据,那么您可以得到其中的任何一个。
旧版本要求(正如Adam Marczak所指出的):
from azure.storage.blob import BlobClient
blob = BlobClient.from_connection_string("my_connection_string", container="mycontainer", blob="my_blob")
with open("./SampleSource.txt", "rb") as data:
blob.upload_blob(data)而新的:
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name, account_key)
blob_service.create_blob_from_path(
container_name, blob_name , full_file_path )https://stackoverflow.com/questions/57816849
复制相似问题