首页 > 解决方案 > 无法以编程方式下载 Blob

问题描述

我们在 azure 存储容器中有多个 blob,当我们使用 powershell 下载 blob(文件)时,9 个文件中有 8 个下载,但是第 9 个失败。这个文件绝对没有什么不同,我在 blob 属性中注意到的唯一一件事是“内容 MD5”是空白的,但是其他 8 个有一个值。不知道这是什么或者它是否与它有任何关系,我希望有人能解释为什么这是一个文件没有下载..

提前致谢 :)

标签: azurepowershell

解决方案


尝试使用以下代码从 Azure Blob 下载文件

function Get-DLLFile
{
    param(
       [Parameter(Mandatory=$true)] [string]   $connectionString,             
       [Parameter(Mandatory=$true)] [String[]] $blobsName,
       [Parameter(Mandatory=$true)] [string]   $container,
       [Parameter(Mandatory=$true)] [string]   $filePath
    ) 


    Try
{
 foreach ($blobName in $blobsName) 
        {

    $file = $filePath + $blobName
    $fileAvailable = Get-Item -Path $file -ErrorAction SilentlyContinue
    if($null -eq $fileAvailable)
    {
        $ctx = New-AzureStorageContext -ConnectionString $connectionString
        New-Item -Path $filePath -ItemType Directory -Force | Out-Null       
        Get-AzureStorageBlobContent -Blob $blobName -Container $container -Destination $filePath -Context $ctx -Force | out-null

    }
    }
}
Catch
{
   $_.Exception.Message
}
}
Get-DLLFile -blobsName "File1.csv","File2.json" -container "myContainer" -connectionString "$(BlobConnectionString)" -filePath "$(System.DefaultWorkingDirectory)/Download"

希望这应该有效,如果没有请分享您遇到的异常。


推荐阅读