I have a method below to read blob file as per the fileName. The file exists in the Azure Blob Storage but still the code is throwing "The specified blob does not exists."
public async Task<string> ReadBlob(string fileName)
{
try
{
CloudBlobClient cloudBlobClient = CloudStorageAccount.Parse(_blobDataConnectionString)
.CreateCloudBlobClient();
var cc = cloudBlobClient.GetContainerReference(_blobDataContainerName);
CloudBlockBlob blockBlob = cc.GetBlockBlobReference(fileName);
return await blockBlob.DownloadTextAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, $"ReadBlob: {ex.Message}");
throw;
}
}
2
Answers
I have modified my Read method and now I am able to read the data from Blob
I too agree with @David Makogon that it is a basic error, but my code works, when blob and container exists, it gives blob data . If not throws an exception saying either of one does not exist and below are my observations:
My blob exists:
After Running the code:
Make sure you give all correct values(filename, container name and connection string). Make sure that the container is accessible. Filename should be given with extension too.