使用 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