I download a blob from storage account to local drive using the following:
$context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey
Get-AzStorageBlobContent -Container $containerName -Blob $blobName -Destination $localPath -Context $context
The $context is returned but when it runs the line Get-AzStorageBlobContent with the parameters i get an error:
Get-AzStorageBlobContent : The condition specified using HTTP conditional header(s) is not met. HTTP Status Code: 412 - HTTP Error Message: The condition specified using HTTP conditional header(s) is not met.
But the file still downloads . How can i fix this error ?
Get-AzStorageBlobContent : The condition specified using HTTP conditional header(s) is not met. HTTP Status Code: 412 - HTTP Error Message: The condition specified using HTTP conditional header(s) is not met.
According to this SO-answer by Gaurav Mantri.
When a
write
operation is done on a blob, theETag
of the Blob is reset, let's say0x8CDA1BF0593B660
. And, before it is triggered(with ETag value0x8CDA1BF0593B660
), the blob is updated by another service, and itsETag
is changed to0x8CDA1BF0593B661
.
Now, the etag
value is changed that might be causing the above error, you can use the -force
parameter to Overwrites an existing file without confirmation.
Command:
$storageAccountName="venkat326123"
$storageAccountKey="T3cxxxxxxp4Wu2+AStD9nyWw=="
$containerName="test"
$blobName="data.png"
$localPath="C:\Users\xxxx\Documents\folder1\sample.png"
$context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Get-AzStorageBlobContent -Container $containerName -Blob $blobName -Destination $localPath -Context $context -Force
Always use the -Force
parameter carefully, as it can cause data loss by overwriting files without asking first.
Output:
AccountName: venkat326123, ContainerName: test
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted VersionId
---- -------- ------ ----------- ------------ ---------- ------------ --------- ---------
data.png BlockBlob xxxxxx application/octet-stream 2024-10-07 08:21:59Z Hot False
Reference: