我想知道是否有办法检查容器中是否存在 blob?
$blob = $blobRestProxy->getBlob("mycontainer", "myblobname");
if($blob){
return 'exists';
} else {
return 'not exists';
}
我已经尝试过此操作,但只要 blob 不存在,我就会收到此消息:
BlobNotFound
The 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/