【发布时间】:2019-08-13 10:08:29
【问题描述】:
我正在从 Azure 存储资源管理器中的多个容器中复制内容并将其写入到一堆新容器中,我想知道最有效的方法。
现有的容器称为循环输入1,循环输入2,....,内容被写入称为循环输出1,循环输出2等的新容器。这些容器都是相同类型的 (jpegs)。
下面的 for 循环创建一个具有所需后缀的新容器(循环输出),然后将相关循环输入容器中的 blob 复制到此处。我有大约 30 个容器,每个容器中有 1000 张图像,所以不确定这是否是最好的方法(它很慢)。有更好的方法吗?
from azure.storage.blob.baseblobservice import BaseBlobService
account_name = 'name'
account_key = 'key'
# connect to the storage account
blob_service = BaseBlobService(account_name = account_name, account_key = account_key)
# get a list of the containers that need to be processed
cycling_containers = blob_service.list_containers(prefix = 'cycling-input')
# check the list of containers
for c in cycling_containers:
print(c.name)
# copy across the blobs from existing containers to new containers with a prefix cycling-output
prefix_of_new_container = 'cycling-output-'
for c in cycling_containers:
contname = c.name
generator = blob_service.list_blobs(contname)
container_index = ''.join(filter(str.isdigit, contname))
for blob in generator:
flag_of_new_container = blob_service.create_container("%s%s" % (prefix_of_new_container, container_index))
blob_service.copy_blob("%s%s" % (prefix_of_new_container, container_index), blob.name, "https://%s.blob.core.windows.net/%s/%s" % (account_name, contname, blob.name))
【问题讨论】:
标签: python python-3.x blob azure-storage azure-blob-storage