【发布时间】:2020-12-04 09:42:31
【问题描述】:
总结问题:
我正在尝试使用 BlobServiceClient 和 Python 将本地文件夹上传到 Blob 存储。 here 和 here 的一些问题不起作用,因为 create_blob_from_path() 在 V12 SDK 中不起作用,我不想回到旧版本。
我的尝试:
我将os.walk 用于本地目录,但缺少最重要的部分,例如类似于create_blob_from_path() 的函数。
示例代码:
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, PublicAccess
import os
base_file_path = '/path/to/my/local/directory/'
connect_str = '1q2w3e4r5t6y'
container_name = 'abc'
try:
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
container_name = 'abc' # already created in Azure
container_client = blob_service_client.get_container_client(container_name)
upload_local_file_path = base_file_path + 'csv-summary-output' # input folder path
for root, subdir, local_file in os.walk(upload_local_file_path):
if local_file:
for name in local_file:
dir_part = os.path.relpath(root, upload_local_file_path)
file_path = os.path.join(root, name)
==> missing parts here
except Exception as ex:
print('Exception:')
print(ex)
非常感谢任何帮助,我将查看 Azure Github,看看那里是否有任何有用的信息。
【问题讨论】:
标签: python azure upload azure-blob-storage