Home > OS >  How to read blob from url using Microsoft.Azure.Storage.Blob?
How to read blob from url using Microsoft.Azure.Storage.Blob?

Time:10-11

I have an existing code that uses Microsoft.Azure.Storage.Blob library to upload the blob in Azure Storage and provide a SAS url to the client. But, we have to change that to read the content of the blob using C# code to do further processing.

I have seen various code to download the file using fileName but none with url. Can someone point me to the code that can read the blob from a url?

This is the code that we use to upload the data.

CloudBlobContainer cloudBlobContainer = _blobStorageHelper.CreateCloudBlobContainer(Id);
CloudBlockBlob cloudBlockBlob = _blobStorageHelper.CreateCloudBlockBlob(cloudBlobContainer, localFileName);
cloudBlockBlob.Properties.ContentType = "application/fhir ndjson";
cloudBlockBlob.UploadFromFile(localFileName);

Now, to download I see that CloudBlockBlob has a method DownloadText() but not sure how can I use it or any other method to read the content from a URL?

CodePudding user response:

You can use CloudBlockBlob(Uri) constructor to create an instance of CloudBlockBlob using a SAS URL. The Uri parameter is the SAS URL.

Other option would be to use CloudBlockBlob(Uri, StorageCredentials) where the Uri parameter is the Blob URL and StorageCredentials is constructed using SAS token.

  • Related