通过 Azure CLI 启用 Azure 存储 CORS 规则
Enabling Azure Storage CORS rule via Azure CLI
我正在尝试使用 Azure CLI 2.0 在我的存储帐户上配置 CORS,但我一直收到错误。
命令:
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
输出:
XML specified is not syntactically valid.
事实证明这是由于来自存储命令的错误消息非常糟糕。如果存储帐户上已经定义了 5 条 CORS 规则,则会出现 XML 错误。
如果你不 运行 进入 XML 错误,上面的命令将打印一个 Python 堆栈跟踪,因为命令需要 --services b
而不是 --services blob
。
解决方法是先清除所有CORS规则,然后添加新规则:
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
正如 lindydonna - msft 提到的,我们需要使用 --services b
而不是 --services blob
。如果我们想为多个服务添加 cors,我们可以组合 bfqt.
The storage service(s) for which to add the CORS rule: (b)lob (f)ile (q)ueue (t)able. Can be combined.
我们可以获得有关 azure storage cors and az storage cors add
from document 的更多详细信息。
我正在尝试使用 Azure CLI 2.0 在我的存储帐户上配置 CORS,但我一直收到错误。
命令:
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
输出:
XML specified is not syntactically valid.
事实证明这是由于来自存储命令的错误消息非常糟糕。如果存储帐户上已经定义了 5 条 CORS 规则,则会出现 XML 错误。
如果你不 运行 进入 XML 错误,上面的命令将打印一个 Python 堆栈跟踪,因为命令需要 --services b
而不是 --services blob
。
解决方法是先清除所有CORS规则,然后添加新规则:
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
正如 lindydonna - msft 提到的,我们需要使用 --services b
而不是 --services blob
。如果我们想为多个服务添加 cors,我们可以组合 bfqt.
The storage service(s) for which to add the CORS rule: (b)lob (f)ile (q)ueue (t)able. Can be combined.
我们可以获得有关 azure storage cors and az storage cors add
from document 的更多详细信息。