Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.22k stars 3.83k forks source link

Set Blob Metadata API call doesn't restrict users to define null as value for metadata however Set-AzStorageBlobContent imposing restrictions #22506

Open GaneshMSFT opened 1 year ago

GaneshMSFT commented 1 year ago

Description

Set Blob Metadata API doesn't restrict users to define null as value for metadata. However, PS cmdlet Set-AzStorageBlobContent have validations in place so that users won't set null value. I see this behavior inconsistency in direct API calls vs PS. Can you please fix this?

Issue script & Debug output

$Metadata = @{
    "Description" = ""    
}

Start-Transcript
$DebugPreference = 'continue'
# Upload the blob with metadata
Set-AzStorageBlobContent -Context $Context -Container $ContainerName  -Blob $BlobName -File $LocalFilePath -Metadata $Metadata
Stop-Transcript

Environment data

$PSVersionTable

Name                           Value                                                                                                                                     
----                           -----                                                                                                                                     
PSVersion                      5.1.23516.1000                                                                                                                            
PSEdition                      Desktop                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                   
BuildVersion                   10.0.23516.1000                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                           
WSManStackVersion              3.0                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                       
SerializationVersion           1.1.0.1

Module versions

Get-Module Az*

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Script     2.12.1     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                       
Script     5.4.1      Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkR...

Error output

Set-AzStorageBlobContent : The argument must not be empty string.
At line:4 char:1
+ Set-AzStorageBlobContent -Context $Context -Container $ContainerName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzStorageBlobContent], StorageException
    + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand
Set-AzStorageBlobContent : The argument must not be empty string.
ghost commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

blueww commented 1 year ago

For Powershell, the limitation is from an old SDK limitation. You can work around it by set the blob meta data after uploading it as following script:

$meta = New-Object System.Collections.Generic.Dictionary"[String,String]"
$meta.Add("Description","")

$b = Get-AzStorageBlob -Context $Context -Container $ContainerName  -Blob $BlobName
# or : $b =  Set-AzStorageBlobContent -Context $Context -Container $ContainerName  -Blob $BlobName -File $LocalFilePath -Metadata $Metadata

$b.BlobClient.SetMetadata($meta) 

We will investigate how to fix it for longer term.

microsoft-github-policy-service[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.