Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CloudBlockBlob.Exists() method always returns false

Tags:

c#

azure

So I have uploaded a file into my Azure storage account and now I am trying to delete it, so I have the method.

try
{
    var exists = Blob.Exists(); //Always False
    var t = Blob.DeleteIfExistsAsync(DeleteSnapshotsOption.IncludeSnapshots, null, null, new OperationContext());
    if (!t.Result) // t.Result is Always False
    {
         Blob.DeleteAsync(DeleteSnapshotsOption.IncludeSnapshots, null, null, new OperationContext());
    }
}
catch (Exception ex)
{
    //No 404 error thrown for DeleteAsync (Proves blob must exist)
}

but my Blob.Exists() method always returns false even though I can see the blob in my storage account through the portal. What does the Exist method actually do? The only information msdn gives is:

Checks existence of the blob.

After the DeleteIfExistsAsync method returns false because apparently the blob doesn't exist I use DeleteAsync and this removes the file from my storage account, also more importantly doesn't throw a 404 error which is ususally thrown if no blob is there to delete or access permissions are incorrect.

why do Blob.Exists and Blob.DeleteIfExists always return false?

like image 569
User1 Avatar asked Mar 11 '15 15:03

User1


1 Answers

This was a problem with my SharedAccessSignature previously I had

var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
          {
              Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Delete,
              SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(Convert.ToDouble(ConfigurationManager.AppSettings["SharedAccessSignatureExpiryTimeOffset"]))
          });

but I needed to add SharedAccessBlobPermissions.Read to my SharedAccessSignature. With the extra read permission Exists() now returns true

like image 93
User1 Avatar answered Oct 19 '22 05:10

User1