Azure Storage - Uploading .zip file with PowerShell

I have an Azure DevOps build pipeline that includes a PowerShell task. That task uploads a file to Azure Storage. At this time, I've created the following script:

PowerShell Script

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

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

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

This script successfully runs on my local machine and in Azure DevOps. While I can see the file in my Azure Storage account, it seems corrupted.

From the Azure Portal, I choose "Download" from the file blob context menu. The file gets downloaded to my machine. I then try to unzip the archive file by selecting "Expand All..." from the File Explorer on Windows. When I do that, I receive an error that says:

Windows cannot open the folder.

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

Why does this archive file seem corrupt? It's fine on my local machine. But, when I download it from the Azure Portal, I can't extract the contents of the archive. What am I missing? Thank you for your help.

1 answer

  • answered 2018-09-18 02:20 Joy Wang

    The issue seems caused by blob storage itself, I can reproduce your issue on my side.

    Even if upload and download the compressed file(have test .zipand .rar type) manually in the portal(also test with v1 andv2 tier of storage account), it also gives the error.

    You could open a issue in the github, besides, if it is possible, you could use file storage to do that, Managing Azure file shares with Azure PowerShell, it will work fine.


    It may be a bug of azure portal, I download the compressed file in the storage explorer and upzip it, it works fine. So you could try to use storage explorer to do it.