更改 Microsoft Azure Blob 的默认服务版本 - PHP

Change Default Service Version of Microsoft Azure Blob - PHP

$this->blobClient = ServicesBuilder::getInstance()
                                ->createBlobService($azureString);

$properties = $this->blobClient->getServiceProperties();

如何更改 Microsoft Azure 的默认服务版本?

目前设置为2009-09-19。我想改成2012-02-12

谢谢。

你的意思是STORAGE_API_LATEST_VERSION? It is set to 2015-04-05 在最新的 SDK 版本 (v 0.14.0) 中。

但是,您可以在以下位置更改它:

vendor\microsoft\azure-storage\src\Common\Internal\Resources.php 

编辑:

根据 Azure's documentation

If a request to the Blob service does not specify the x-ms-version header, and the default version for the service has not been set using Set Blob Service Properties, then the earliest version of the Blob service is used to process the request. However, if the container was made public with a Set Container ACL operation performed using version 2009-09-19 or newer, then the request is processed using version 2009-09-19.

因此您可以指定 x-ms-version header 以通过 Postman 更改 DefaultServiceVersion

为了扩展 Aaron Chen 的答案,您实际上可以永久 set the default service version,这样您就不必提供 x-ms-version 请求 header 以获得 public 请求的更新功能(例如“Accept-Ranges: bytes” header)。但这有点麻烦,因为几乎没有 SDK 实际上支持设置这个 属性。对我有用的是使用以下 PowerShell 代码。 仅适用于 Windows(其他平台的 DotNetCore-Azure 模块也不支持),但它可以使用 Cloud Shell 在 Azure 门户中,如果您无权访问 Windows 环境。

云端Shell:

PS Azure:\> $ctx = New-AzureStorageContext -StorageAccountName <account-name> -StorageAccountKey <key>
Azure:\
PS Azure:\> Update-AzureStorageServiceProperty -ServiceType Blob -DefaultServiceVersion 2017-07-29 -Context $ctx

对于所有未提供的请求,这会将存储帐户服务的默认版本设置为 2017-07-29(撰写本文时的最新版本)他们自己的 x-ms-version header。看到这个 list for an overview of the different versions available

在 Windows PowerShell 环境中,您还必须安装 Azure 模块:

作为管理员:

Install-Module -Name AzureRM -AllowClobber
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

作为用户

Import-Module Azure.Storage
$ctx = New-AzureStorageContext -StorageAccountName <account-name> -StorageAccountKey <key>
Update-AzureStorageServiceProperty -ServiceType Blob -DefaultServiceVersion 2017-07-29 -Context $ctx