我有一个包含 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 门户下载它时,我无法提取存档的内容。我缺少什么?感谢您的帮助。
最佳答案
该问题似乎是由 blob 存储本身引起的,我可以在我这边重现您的问题。
即使在门户中手动上传和下载压缩文件(有测试 .zip
和 .rar
类型)(也使用 v1
进行测试) > 和v2
存储帐户层),它也会给出错误。
你可以在github上提出一个问题,另外,如果可能的话,你可以使用file storage为此,Managing Azure file shares with Azure PowerShell ,它会工作得很好。
更新:
这可能是azure门户的一个错误,我在存储资源管理器中下载了压缩文件并对其进行了压缩,它工作得很好。所以你可以尝试使用storage explorer去做这件事。
关于Azure 存储 - 使用 PowerShell 上传 .zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52374734/