@angeline mary marchella Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
Apologies for the delay response!
The issue you are experiencing with the ExistsAsync()
method always returning false could be caused by a few different factors. Here are a few things you can check:
- Check the container and blob names: Make sure that the container and blob names are spelled correctly and match the names in your Azure Blob Storage account. It's possible that there is a typo or a naming mismatch that is causing the
ExistsAsync()
method to fail. - Check the connection string: Make sure that the connection string you are using to create the
BlobServiceClient
object is correct and includes the correct account name and account key. You can verify this by checking the connection string in the Azure portal or by using the Azure Storage Explorer tool. - Check the permissions: Make sure that the account key you are using to authenticate with Azure Blob Storage has the necessary permissions to read the container and blob. You can check this by verifying the access policies in the Azure portal or by using the Azure Storage Explorer tool.
- Check the blob tier: Make sure that the blob you are trying to access is not in the Archive tier. Blobs in the Archive tier are not immediately accessible and must be rehydrated before they can be read. You can check the blob tier in the Azure portal or by using the Azure Storage Explorer tool.
BlobBaseClient.ExistsAsync(CancellationToken) Method
BlobClient.Exists() throws exception when blob is missing
var blobServiceClient = new BlobServiceClient(connectionString);
var containerClient = blobServiceClient.GetBlobContainerClient(containerName);
var blobClient = containerClient.GetBlobClient(blobName);
var isExist = await blobClient.ExistsAsync();
if (isExist)
{
Console.WriteLine("Blob exists.");
}
else
{
Console.WriteLine("Blob does not exist.");
}
If none of these solutions work, you can try using the DownloadAsync()
method to download the blob directly instead of checking if it exists first. If the blob does not exist, the DownloadAsync()
method will throw a RequestFailedException
with a status code of 404 (Not Found).
Please let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.