Azure:使用存储 API 查找存储是常规存储还是 Blob 存储



有没有办法使用 Azure 存储 Java API 确定存储帐户是 blob 存储还是常规用途存储

根据 Azure 存储 REST APICreate Storage Account(仅限版本 2016-01-01 及更高版本),可以看到一个参数kind,用于确定将在请求正文中创建哪种存储帐户(StorageBlobStorage)。

若要使用 Azure 存储 Java API,有一个枚举类Kind其中包含两种类型的存储帐户,可以通过StorageAccount.DefinitionStages接口的两个接口(WithGeneralPurposeAccountKindWithBlobStorageAccountKind)选择所需的一种。

以下是它们的通常用法。

  1. 通过define方法创建默认类型的存储帐户,请参阅此处的完整示例代码。

    StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName)
    .withRegion(Region.US_EAST)
    .withNewResourceGroup(rgName)
    .create();
    

    根据define方法的源代码,默认类型的存储帐户是通过WithGeneralPurposeAccountKindStorage

  2. 创建BlobStorage类型的存储帐户。

    StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName)
    .withBlobStorageAccountKind() // Set the kind as `BlobStorage`
    .withRegion(Region.US_EAST)
    .withNewResourceGroup(rgName)
    .create();
    

最新更新