检查 Azure 存储中是否存在 Blob [英] Checking if a blob exists in Azure Storage

查看:30
本文介绍了检查 Azure 存储中是否存在 Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题(希望如此!) - 我只想找出特定容器中是否存在 blob(具有我定义的名称).如果确实存在,我会下载它,如果不存在,我会做其他事情.

I've got a very simple question (I hope!) - I just want to find out if a blob (with a name I've defined) exists in a particular container. I'll be downloading it if it does exist, and if it doesn't then I'll do something else.

我已经在 intertubes 上进行了一些搜索,显然曾经有一个名为 DoesExist 或类似的函数......但与许多 Azure API 一样,这似乎不再存在(或者如果它是,有一个非常巧妙的伪装名称).

I've done some searching on the intertubes and apparently there used to be a function called DoesExist or something similar... but as with so many of the Azure APIs, this no longer seems to be there (or if it is, has a very cleverly disguised name).

推荐答案

新 API 具有 .Exists() 函数调用.只需确保您使用 GetBlockBlobReference,它不会执行对服务器的调用.它使功能变得如此简单:

The new API has the .Exists() function call. Just make sure that you use the GetBlockBlobReference, which doesn't perform the call to the server. It makes the function as easy as:

public static bool BlobExistsOnCloud(CloudBlobClient client, 
    string containerName, string key)
{
     return client.GetContainerReference(containerName)
                  .GetBlockBlobReference(key)
                  .Exists();  
}

这篇关于检查 Azure 存储中是否存在 Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆