【问题标题】:Upload folder in Blob Storage with SAS URI使用 SAS URI 在 Blob 存储中上传文件夹
【发布时间】:2021-04-23 07:43:30
【问题描述】:

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

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

在此感谢您

【问题讨论】:

    标签: python upload azure-blob-storage


    【解决方案1】:

    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

    【讨论】:

    • 谢谢。有用。现在我想看看我通过 python 脚本上传到容器中的文件。是否有任何脚本可以做到这一点?
    猜你喜欢
    • 2023-03-25
    • 2021-04-30
    • 1970-01-01
    • 2021-08-31
    • 2021-10-22
    • 1970-01-01
    • 2015-05-27
    • 2019-09-11
    • 2023-03-08
    相关资源
    最近更新 更多