使用 Get-AzureStorageBlobContent 从 Azure 下载 - 内容出现乱码

Downloading from Azure with Get-AzureStorageBlobContent - contents are garbled

我正在使用此脚本下载 Azure 存储容器的内容: http://bearprocess.com/2014/03/12/Download-All-Blobs-From-Container-Using-Powershell-In-Azure-Stroage/

$container_name = 'packageitems'
$destination_path = 'C:\pstest'
$connection_string = 'DefaultEndpointsProtocol=https;AccountName=[REPLACEWITHACCOUNTNAME];AccountKey=[REPLACEWITHACCOUNTKEY]'

$storage_account = New-AzureStorageContext -ConnectionString $connection_string

$blobs = Get-AzureStorageBlob -Container $container_name -Context $storage_account

foreach ($blob in $blobs)
{
    New-Item -ItemType Directory -Force -Path $destination_path

    Get-AzureStorageBlobContent `
    -Container $container_name -Blob $blob.Name -Destination $destination_path `
    -Context $storage_account

}

基本上,它工作正常,我拥有所有文件及其文件夹结构,正如我所期望的那样。 但问题是:文件内容全是乱码! 它们看起来像这样:

hE4P®dÊÐk–ŠO`‡Þ¿¯ýT¸J\NÝ:Këþ̘4¶êΛ/µ¥Ñ樌öÑŠ'Œþ¼èÓ«@$;ðWc•óÖ   

我想我遗漏了一些关于编码的信息,但我找不到任何相关信息。 我正在下载的文件是 html 个文件、js 文件和一些图像。 我不知道我在这里做错了什么。

当返回的内容不是您可以阅读的内容时,就会发生这种情况。它可以是图片、压缩文件等。请检查博客上的内容是否可读,并且不是压缩格式或任何不可读格式。

更新: 从 Gaurav 的评论中注意到该问题已经解决,并且确实与以 GZIP 格式压缩的内容有关。