Change Default Service Version of Microsoft Azure Blob - PHP

送分小仙女□ 提交于 2019-12-12 02:43:49

问题


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

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

How can i change the default service version of microsoft azure?

Currently it is set at 2009-09-19. i want to change it to 2012-02-12.

Thanks.


回答1:


You mean STORAGE_API_LATEST_VERSION? It is set to 2015-04-05 in the latest SDK version (v 0.14.0).

However, you can change it at:

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

EDIT:

Per 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.

So you can specify the x-ms-version header to change DefaultServiceVersion via Postman.




回答2:


To expand on Aaron Chen's answer, you can actually set the default service version permanently, so that you don't have to provide the x-ms-version request header to get newer features for public requests (like "Accept-Ranges: bytes" header for example). It is a bit of a hassle though, because almost no SDK actually supports setting this property. What worked for me is to use the following PowerShell code. It's for Windows only (the DotNetCore-Azure modules for other platforms do not support that either), but it works using the Cloud Shell within Azure Portal if you don't have access to a Windows environment.

Within Cloud Shell:

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

This will set the default version of the storage account's service to 2017-07-29 (the newest at the time of this writing) for all requests which don't provide their own x-ms-version header. See this list for an overview of the different versions available.

Within a Windows PowerShell environment you have to install the Azure modules as well:

As an admin:

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

As a user

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


来源:https://stackoverflow.com/questions/43335176/change-default-service-version-of-microsoft-azure-blob-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!