Azure CloudBlockBlob.DeleteIfExists() - false 是否始终意味着 blob 不存在?

标签 azure azure-storage azure-blob-storage

我知道如果 blob 存在,CloudBlockBlob.DeleteIfExists() 将返回 true,如果不存在,则返回 false。

但是,我很好奇,如果 blob 确实存在,但 Azure 中出现问题,导致文件删除无法发生(我找不到有关该行为的任何文档),会发生什么。

我担心它会返回 false 而不是抛出某种异常,因此我相信 blob 已被删除,而实际上它仍然存在。

简而言之,如果我得到 false 值,是否始终意味着该 blob 不存在,无需删除,我会如果 Azure 端出现问题,会出现某种异常吗?

谢谢。

最佳答案

查看该方法的源代码here ,如果 blob 被删除,您将得到 true;如果 blob(或 blob 容器)不存在,您将得到 false。在所有其他情况下(假设 blob 已被租用,因此无法删除),将会引发异常。相关代码如下:

    public virtual bool DeleteIfExists(DeleteSnapshotsOption deleteSnapshotsOption = DeleteSnapshotsOption.None, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
    {
        BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.Unspecified, this.ServiceClient);
        operationContext = operationContext ?? new OperationContext();

        try
        {
            this.Delete(deleteSnapshotsOption, accessCondition, modifiedOptions, operationContext);
            return true;
        }
        catch (StorageException e)
        {
            if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound)
            {
                if ((e.RequestInformation.ExtendedErrorInformation == null) ||
                    (e.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.BlobNotFound) ||
                    (e.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.ContainerNotFound))
                {
                    return false;
                }
                else
                {
                    throw;
                }
            }
            else
            {
                throw;
            }
        }
    }  

关于Azure CloudBlockBlob.DeleteIfExists() - false 是否始终意味着 blob 不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48105181/

相关文章:

azure - 在 VS2015 中打开 Azure DataFactory 项目

azure - Azure-Storage-Net 更改日志中 CoreCLR、PCL 和 WinRT 的重要性是什么

rest - 实现 Azure Rest api 的 Put block ?

javascript - 如何在 asp.net 中使用 javascript 在 Azure BLOB 存储上上传期间压缩视频?

azure - 如何通过组织帐户或 Active Directory 访问 Azure Server

azure - Terraform - 功能创建 Swift 虚拟网络不允许用于免费试用订阅 - 在即用即付订阅中

Azure函数应用程序: what's the feature to publish a Docker container about?

python - 上传到 Azure Blob 存储时设置内容类型

python - 在 Python 中通过 SAS 导入 azure blob

azure - Kubernetes 使用 Azure Blob 存储