Azure存储 - 使用PowerShell上传.zip文件

问题描述 投票:1回答:1

我有一个包含PowerShell任务的Azure DevOps构建管道。该任务将文件上载到Azure存储。这时,我创建了以下脚本:

PowerShell脚本

New-Item -ItemType directory -Path ./test
New-Item -Path ./test -Name "file.txt" -ItemType "file" -Value "hello world"

Compress-Archive -Path ./test/* -DestinationPath ./test.zip

$azureStorageKey = "<MyAccessKey>"
$storage_context = New-AzureStorageContext -StorageAccountName "mystorageaccount" -StorageAccountKey "$azureStorageKey"
Set-AzureStorageBlobContent -Context $storage_context -Container "mycontainer" -File "./test.zip" -Blob "temp/test.zip" -Force

此脚本在我的本地计算机和Azure DevOps中成功运行。虽然我可以在Azure存储帐户中看到test.zip文件,但它似乎已损坏。

从Azure门户,我从test.zip文件blob上下文菜单中选择“下载”。 test.zip文件被下载到我的机器上。然后,我尝试通过从Windows上的文件资源管理器中选择“全部展开...”来解压缩存档文件。当我这样做时,我收到一条错误消息:

Windows cannot open the folder.

The Compressed (zipped) Folder 'C:\Users\me\Downloads\test.zip' is invalid.

为什么这个档案文件看起来很腐败?这在我的本地机器上很好。但是,当我从Azure门户下载它时,我无法提取存档的内容。我错过了什么?谢谢您的帮助。

azure powershell azure-storage azure-storage-blobs
1个回答
1
投票

问题似乎是由blob存储本身引起的,我可以在我这边重现你的问题。

即使在门户中手动上传和下载压缩文件(测试.zipand .rar类型)(也使用v1v2层存储帐户进行测试),它也会给出错误。

您可以在github中打开一个问题,此外,如果有可能,您可以使用file storage来做到这一点,Managing Azure file shares with Azure PowerShell,它会正常工作。

更新:

它可能是天蓝色门户网站的错误,我在存储资源管理器中下载压缩文件并将其上传,它工作正常。所以你可以尝试使用storage explorer来做到这一点。

© www.soinside.com 2019 - 2024. All rights reserved.