php - 检查 Azure 中是否存在 blob

标签 php azure azure-storage azure-blob-storage

我想知道是否有办法检查容器中是否存在 blob?

    $blob = $blobRestProxy->getBlob("mycontainer", "myblobname");
    if($blob){
        return 'exists';
    } else {
        return 'not exists';
    }

我已经尝试过此操作,但只要 blob 不存在,我就会收到此消息:

BlobNotFoundThe specified blob does not exist.

如果存在,代码自然返回“存在”。我对列出容器中的所有 blob 并迭代直到找到匹配项不感兴趣,因为我有很多 blob。

最佳答案

当blob不存在时,函数getBlob将引发ServiceException异常并退出PHP进程,以下代码将不起作用。

请尝试在您的代码中添加 try catch 语句,例如

try {
    $blob = $tableRestProxy->getBlob("mycontainer", "myblobname");
    return 'exists';
} catch (ServiceException $e) {
    return 'not exists';
} 

关于php - 检查 Azure 中是否存在 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37297646/

相关文章:

php - 路线 :list - 404 error on oauth/token 中缺少 Laravel Passport 路线

php - 使用 PHP 代码从 URL 下载图像?

IoT 中心和诊断设置的 Azure 模板部署不起作用

node.js - Nodejs Azure 存储将 Blob 复制到新 Blob

c# - 使用 .NET Core 的 Azure 队列存储 WebJob

java - 无法更新行

azure - Azure 表存储中table.Execute 中的OperationContext 的基本用途是什么?

iis - windows azure 或 IIS 初始加载缓慢

Azure VHD 文件和页面 blob

javascript - 如何在 Laravel 或 Django 的 Web 应用程序中实现指纹