4

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Is there a way to get account-name and account-key from the connection string? I don't want to use the BlobContainerClient because I need to access the Blob directly by it's URI ;-). In my case I don't have the container name, only the Blob URI.
You can get the key and value from the connection string, just parse the connection string. The connection string is in this format: DefaultEndpointsProtocol=https;AccountName=<your-account-key>;AccountKey=<your-account-key>;EndpointSuffix=core.windows.net
For those following along with Node.JS, you can't use a connection string like so new BlobServiceClient(connectionString);. You have to use BlobServiceClient.fromConnectionString(connectionString);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.