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:
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
This script successfully runs on my local machine and in Azure DevOps. While I can see the
test.zip file in my Azure Storage account, it seems corrupted.
From the Azure Portal, I choose "Download" from the
test.zip file blob context menu. The
test.zip 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\test.zip' 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.
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
.rartype) manually in the portal(also test with
v2tier of storage account), it also gives the error.
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.