Access blob by URI using Storage Connection String in C# SDK

Viewed 2695

I'm using the Azure.Storage.Blobs SDK version 12.7 in C# with .net core and I want to access a blob directly by it's URI using the blob storage connection string for deletion.

How would I do that? I assume I can use the BlobClient class, which constructor takes the URI, but then im not authorized. The constructor takes also a StorageSharedKeyCredential, but how can I create it from the connection string?

1 Answers

You can create StorageSharedKeyCredential in this way. Note that it uses the key instead of the connection string:

StorageSharedKeyCredential storageSharedKeyCredential = new StorageSharedKeyCredential(<your-account-name>,<your-account-key>)

You can refer to this official document.

By the way, if you want to use connection string, you can use this way:

BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(<you-container-name>)

BlobClient blobClient = containerClient.GetBlobClient(fileName);

Please refer to this official document.

Related