joa*_*ofe 5 c# azure azure-storage azure-storage-blobs
我正在使用Azure的C#管理API在云中创建资源。我被困在Blob存储中创建一个容器。我确实按照以下说明创建了存储帐户:
// 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();
Run Code Online (Sandbox Code Playgroud)
但是我不知道该怎么做。从Microsoft文档看来,我必须检索一个Microsoft.WindowsAzure.Storage.CloudStorageAccount实例,但是通过storageAccount上述代码获得的实例位于命名空间中Microsoft.Azure.Management.Storage.Fluent,并且我还没有找到任何CloudStorageAccount从那里获取该值的方法。
是否可以在流畅的名称空间中直接使用API创建容器?如果没有,如何CloudStorageAccount从我的实例中获取实例IStorageAccount?
SO中的这个答案没有帮助,因为它确实Microsoft.WindowsAzure直接使用了名称空间。
是否可以在流畅的名称空间中直接使用API创建容器?如果没有,如何从IStorageAccount之一获取CloudStorageAccount实例?
至少到今天为止,这是不可能的。在Azure中管理存储帐户时,有两个REST API- Storage Resource Provider REST API和Storage Service REST API。前者负责存储帐户本身的管理(如创建/更新等),后者负责存储帐户中的数据。您可以说前者API处理控制平面,后者处理数据计划。Blob容器的创建属于后一类。
Fluent API您提到的是包装器,Storage Resource Provider API而Microsoft.WindowsAzure.Storage库是包装器Storage Service REST API。您需要在项目中引用该库以创建Blob容器。
您可以做的是使用Fluent API获取访问密钥(密钥1或密钥2)。获得密钥后,将创建一个CloudStorageAccount使用Microsoft.WindowsAzure.Storage库的实例,并使用该库创建一个Blob容器。我知道这不是您要寻找的答案,但是不幸的是,这是今天的唯一方法。