c# - 使用 Fluent API 在 C# 中创建 Blob 存储容器

标签 c# azure azure-storage azure-blob-storage

我正在使用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 APIStorage Service REST API 。前者处理存储帐户本身的管理(如创建/更新等),而后者处理存储帐户中的数据。你可以说前者处理控制平面,后者处理数据计划。 Blob 容器的创建属于后一类。

您提到的

Fluent APIStorage 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/

相关文章:

c# - sqlite专家个人的日期时间错误

c# - 使用 system.text.json 从分块字符串数组中反序列化非常大的 json

azure 虚拟机创建失败

c# - 此版本的存储模拟器不支持此请求的 REST 版本

c# - 在存储帐户之间复制 blob

c# - 在 DLL 中编译类并在 C# 中的另一个项目中引用它

c# - 使用 Task.Run 调用异步方法似乎是错误的?

azure - 无法到达 erlang 端口映射器(服务器端口打开并通过 Telnet 连接)

c# - 构建 Service Fabric Web Api 时出现错误,无法从 Fabric.StatelessServiceContext 转换为 Fabric.ServiceInitializationParameters

azure - 在 Azure 表存储中存储应用程序日志的策略