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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With