【发布时间】:2021-10-13 22:48:40
【问题描述】:
我正在尝试从我的 API 合并 blob 上传。于是创建了存储帐户和容器。
并且身份验证模式设置为 Azure AD。在我们的组织政策中,我们被限制使用连接字符串
但是关于从 blob 上传/下载的教程中有 90% 使用的是 Connectionstring .NET Core Blob access
但由于我是基于 Azure AD 的,我真的很困惑如何继续
我尝试过这种方式,但很晚我发现它在 .net 5 中不支持
var tokenCredential = new TokenCredential(_StorageAuth.AccessToken, TokenRenewerAsync, null, tokenExpiry);
string blobcontainer = "blob-container-dev-dv1";
string storageName = "apllmyappdevuksst";
var storageAccount = new CloudStorageAccount(new StorageCredentials(tokenCredential), storageName, null, true);
//Uri accountUri = new Uri(storageAccount.BlobStorageUri.ToString());
//BlobServiceClient client = new BlobServiceClient(accountUri, new DefaultAzureCredential());
我真的不知道接下来如何从 .NET core 5 将文件上传到 blob
令牌和存储范围的一切都正确
【问题讨论】:
-
我的示例应用可能会有所帮助:github.com/juunas11/managedidentity-filesharing/blob/…
-
你试过
thisBlobServiceClient的构造函数吗? -
根据docs.microsoft.com/en-us/azure/storage/common/…,它说使用 DefaultAzureCredential
-
DefaultAzureCredential是TokenCredential的一种类型,因此可以使用。我建议在这里阅读它 - docs.microsoft.com/en-us/dotnet/api/… 以更好地了解它的实际工作原理。 -
哦,一旦你有了 BlobServiceClient,你就可以使用你分享的链接中提到的相同代码。从那时起,一切都会完全一样。
标签: azure .net-core azure-blob-storage .net-5