4

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.

Community
  • 1
  • 1
Sam
  • 13,934
  • 26
  • 108
  • 194

1 Answers1

8

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);
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • 3
    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. – Sam Jun 17 '20 at 08:44
  • @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 Jul 13 '21 at 12:15
  • @dinotom - You will need to ask SDK team this question :). You can raise an issue on the SDK's Github repo. – Gaurav Mantri Jul 13 '21 at 12:17