I'm trying to configure CORS on my storage account with the Azure CLI 2.0, and I keep getting an error.
Command:
az storage cors add --connection-string $connstr --origins '*' --methods GET --allowed-headers 'x-ms-meta-abc,content-type,x-ms-blob-type,x-ms-meta-data*,x-ms-meta-target*' --exposed-headers 'x-ms-meta-*' --max-age 200 --services blob
Output:
XML specified is not syntactically valid.
It turns out this is due to very poor error messages from the Storage commands. You get an XML error if there are already 5 CORS rules defined on the storage account.
If you don't run into the XML error, the command above will print a Python stacktrace, because the command requies --services b
instead of --services blob
.
The solution is to clear all CORS rules first, then add the new one:
az storage cors clear --services b --connection-string $connstr
az storage cors add --connection-string $connstr --origins '*' --methods GET --allowed-headers 'x-ms-meta-abc,content-type,x-ms-blob-type,x-ms-meta-data*,x-ms-meta-target*' --exposed-headers 'x-ms-meta-*' --max-age 200 --services blob