我正在使用C# management API of Azure在云中创建我的资源。我被困在 blob 存储中创建一个容器。我确实按照 these instructions 创建了一个存储帐户:
// storageAccount here is a Microsoft.Azure.Management.Storage.Fluent.IStorageAccount instance
var storageAccount = _azure.StorageAccounts
.Define(name)
.WithRegion(region)
.WithExistingResourceGroup(resourceGroup)
.WithBlobEncryption()
.WithOnlyHttpsTraffic()
.WithBlobStorageAccountKind()
.WithAccessTier(AccessTier.Hot)
.Create();
但我不知道如何继续下去。来自 Microsoft documentation看来我必须检索一个 Microsoft.WindowsAzure.Storage.CloudStorageAccount
实例,但我使用上述代码获得的 storageAccount
实例位于命名空间 Microsoft 中。 Azure.Management.Storage.Fluent
,我还没有找到任何方法从那里获取CloudStorageAccount
。
是否可以直接使用 Fluent 命名空间中的 API 创建容器?如果没有,如何从我的 IStorageAccount
实例获取 CloudStorageAccount
实例?
This answer in SO没有帮助,因为它直接使用 Microsoft.WindowsAzure
命名空间。
最佳答案
Is it possible to create containers directly with the API in the fluent namespace? If not, how do I get the CloudStorageAccount instance from my IStorageAccount one?
至少到今天为止,这是不可能的。在管理 Azure 中的存储帐户时,有两个 REST API - Storage Resource Provider REST API
和 Storage Service REST API
。前者处理存储帐户本身的管理(如创建/更新等),而后者处理存储帐户中的数据。你可以说前者处理控制平面,后者处理数据计划。 Blob 容器的创建属于后一类。
Fluent API
是 Storage Resource Provider API
的包装器,而 Microsoft.WindowsAzure.Storage
库是 的包装器存储服务 REST API
。您需要在项目中引用此库来创建 blob 容器。
您可以使用 Fluent API 获取访问 key ( key 1 或 key 2)。获得 key 后,您将使用 Microsoft.WindowsAzure.Storage 库创建一个 CloudStorageAccount
实例,并使用该实例创建一个 Blob 容器。我知道这不是您正在寻找的答案,但不幸的是这是迄今为止唯一的方法。
关于c# - 使用 Fluent API 在 C# 中创建 Blob 存储容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48988814/