1

Consider the following code:

// _blobContainerClient is an instance of BlobContainerClient
await _blobContainerClient.UploadBlobAsync(uniqueName, stream);

string uri = < how to get the URI? >

How do I get the URI of the uploaded blob?

I am using Azure.Storage.Blobs 12.8.0.

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
  • Is this helpful - [Click here](https://stackoverflow.com/questions/16961933/how-to-get-blob-url-after-file-upload-in-azure/16962331])? – Salvatore Feb 23 '21 at 12:06

2 Answers2

4

You just need to create a client and return the Uri this,

var blob = new BlobClient(connectionString, containerName, fileName);
await blob.UploadAsync(fileStream, o);
return ReturnUri(blob.Uri);
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
2

If you want to do more things with the blob object, I would recommend creating a new BlobClient. If you just need the URI this should work as well:

var blobUri = $"{_blobContainerClient.Uri.AbsoluteUri}/{uniqueName}";

silent
  • 14,494
  • 4
  • 46
  • 86
  • 2
    thanks! wasn't aware of this URI pattern. for other readers, I found this later: https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#resource-uri-syntax – stefan.at.kotlin Feb 23 '21 at 13:10