在 C# SDK 中使用存储连接字符串通过 URI 访问 blob
Access blob by URI using Storage Connection String in C# SDK
我在带有 .net 核心的 C# 中使用 Azure.Storage.Blobs SDK 版本 12.7,我想使用用于删除的 blob 存储连接字符串通过它的 URI 直接访问 blob。
我该怎么做?
我假设我可以使用 BlobClient
class,哪个构造函数采用 URI,但我没有被授权。构造函数也采用 StorageSharedKeyCredential
,但我如何从连接字符串创建它?
您可以通过这种方式创建StorageSharedKeyCredential
。请注意,它使用 the key instead of the connection string:
StorageSharedKeyCredential storageSharedKeyCredential = new StorageSharedKeyCredential(<your-account-name>,<your-account-key>)
你可以参考这个official document。
顺便说一句,如果你想使用连接字符串,你可以这样使用:
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(<you-container-name>)
BlobClient blobClient = containerClient.GetBlobClient(fileName);
请参考这个official document。
我在带有 .net 核心的 C# 中使用 Azure.Storage.Blobs SDK 版本 12.7,我想使用用于删除的 blob 存储连接字符串通过它的 URI 直接访问 blob。
我该怎么做?
我假设我可以使用 BlobClient
class,哪个构造函数采用 URI,但我没有被授权。构造函数也采用 StorageSharedKeyCredential
,但我如何从连接字符串创建它?
您可以通过这种方式创建StorageSharedKeyCredential
。请注意,它使用 the key instead of the connection string:
StorageSharedKeyCredential storageSharedKeyCredential = new StorageSharedKeyCredential(<your-account-name>,<your-account-key>)
你可以参考这个official document。
顺便说一句,如果你想使用连接字符串,你可以这样使用:
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(<you-container-name>)
BlobClient blobClient = containerClient.GetBlobClient(fileName);
请参考这个official document。