9

I want to create a Azure SDK BlobClient knowing the blob Uri. I can do it like that :

    StorageSharedKeyCredential storageCredential = new StorageSharedKeyCredential("devstoreaccount1", "account key");
    BlobClient bl = new BlobClient(new Uri(blobUri), storageCredential);

But I do not want to use the StorageSharedKey in this case. I want to use the connection string.

However the constructor taking a connection string as first parameter looks like this :

enter image description here

Is there another way to initialize the BlobClient with Blob Uri + connection string ? If not, since all I have as input is the Blob Url, is there a way to parse the Url in order to isolate the container name and the blob name ? I don't see how to identify them.

1 Answer 1

14

Kind of hacky solution but you can try something like this:

        BlobClient blobClient = new BlobClient(new Uri("blob-uri"));
        var containerName = blobClient.BlobContainerName;
        var blobName = blobClient.Name;
        blobClient = new BlobClient(connectionString, containerName, blobName);
Sign up to request clarification or add additional context in comments.

3 Comments

yeah it's a bit hacky :) but I suppose there is no other way around that. A constructor that takes the Uri and connectionString would be nice though.
@Gaurav Mantri...Why is the new SDK creating the client without credentials? The old way you had to create an account object with credentials and then do account.CreateCloudBobClient
@dinotom - You will need to ask SDK team this question :). You can raise an issue on the SDK's Github repo.

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.