使用 SAS URI 上传 Blob 存储中的文件夹

Upload folder in Blob Storage with SAS URI

我必须将一组文件夹上传到 Azure Blob 存储中的专用容器中。 我找到了这个: https://github.com/rahulbagal/upload-file-azure-sas-url 但它仅用于使用专用的 Blob SAS URI 上传文件,而且效果很好。

是否有任何类似的解决方案能够管理文件夹上传而不是文件上传?

先谢谢你

1.请尝试使用此代码:

    import os
    from azure.storage.blob import BlobServiceClient

    account_url = "https://<storage-account-name>.blob.core.windows.net/"
    sas_token = "<your-sas-token>"
    blob_service_client = BlobServiceClient(account_url, sas_token)
    container_name = "<your-container-name>"
    container_client = blob_service_client.get_container_client(container_name)
    local_path = "<your-folder-path>"
    folder_name = "<your-folder-name>"
    for files in os.listdir(local_path):
        with open(os.path.join(local_path,files), "rb") as data:
            blob_client = blob_service_client.get_blob_client(container=container_name, blob= folder_name + "/" + files)
            blob_client.upload_blob(data)

2. 或者您可以使用 azcopy 上传您的文件夹:

例如:

azcopy copy '<folder-path>' 'https://<account-name>.blob.core.windows.net/<container-name>?<sas-token>' --recursive

更详细的可以参考这篇official documentation.