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

标签 azure powershell azure-storage azure-blob-storage

我有一个包含 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/

相关文章:

java - 如何在java中使用LINQ查询Azure表

azure : VNet Integration || The gateway did not receive a response from 'Microsoft.Web'

Azure逻辑应用程序,无法从CreateFile函数获取数据

ios - Microsoft Graph API 问题 iOS : Unable to Complete Request Validation Error

azure - 从另一个 Azure DevOps Git 存储库运行 YAML 管道

function - Powershell:返回函数中没有行的数据表

powershell - 对象属性和变量

c# - 找不到有效的帐户信息组合

PowerShell 'if' 条件

c# - 如果目标中存在 Blob,如何覆盖 Blob