有没有办法使用 Azure 存储 Java API 确定存储帐户是 blob 存储还是常规用途存储
根据 Azure 存储 REST APICreate Storage Account
(仅限版本 2016-01-01 及更高版本),可以看到一个参数kind
,用于确定将在请求正文中创建哪种存储帐户(Storage
或BlobStorage
)。
若要使用 Azure 存储 Java API,有一个枚举类Kind
其中包含两种类型的存储帐户,可以通过StorageAccount.DefinitionStages
接口的两个接口(WithGeneralPurposeAccountKind
和WithBlobStorageAccountKind
)选择所需的一种。
以下是它们的通常用法。
-
通过
define
方法创建默认类型的存储帐户,请参阅此处的完整示例代码。StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName) .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .create();
根据
define
方法的源代码,默认类型的存储帐户是通过WithGeneralPurposeAccountKind
Storage
。 -
创建
BlobStorage
类型的存储帐户。StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName) .withBlobStorageAccountKind() // Set the kind as `BlobStorage` .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .create();