Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 929
Chris Avatar asked Oct 28 '25 15:10

Chris


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.

like image 133
Frank Gong Avatar answered Oct 31 '25 04:10

Frank Gong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!