gpt4 book ai didi

php - 检查 Azure 中是否存在 blob

转载 作者:行者123 更新时间:2023-12-03 05:07:33 25 4
gpt4 key购买 nike

我想知道是否有办法检查容器中是否存在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com