检查 Azure 中是否存在 blob
Check if blob exists in Azure
我想知道是否有办法检查容器中是否存在 blob?
$blob = $blobRestProxy->getBlob("mycontainer", "myblobname");
if($blob){
return 'exists';
} else {
return 'not exists';
}
我已经试过了,但是每当 blob 不存在时我都会收到这条消息:
BlobNotFound
The specified blob does not exist.
如果存在,代码returns自然是'exists'。我对列出容器中的所有 blob 并迭代直到找到匹配项不感兴趣,因为我有很多 blob。
所以:
$exists = $storageClient->blobExists(<container name>, <blob name>);
应该给你想要的。
当 blob 不存在时,函数 getBlob
将引发 ServiceException
异常并退出 PHP 进程,以下代码将不起作用。
请尝试在您的代码中添加 try catch 语句,E.G.
try {
$blob = $tableRestProxy->getBlob("mycontainer", "myblobname");
return 'exists';
} catch (ServiceException $e) {
return 'not exists';
}
我想知道是否有办法检查容器中是否存在 blob?
$blob = $blobRestProxy->getBlob("mycontainer", "myblobname");
if($blob){
return 'exists';
} else {
return 'not exists';
}
我已经试过了,但是每当 blob 不存在时我都会收到这条消息:
BlobNotFound
The specified blob does not exist.
如果存在,代码returns自然是'exists'。我对列出容器中的所有 blob 并迭代直到找到匹配项不感兴趣,因为我有很多 blob。
所以:
$exists = $storageClient->blobExists(<container name>, <blob name>);
应该给你想要的。
当 blob 不存在时,函数 getBlob
将引发 ServiceException
异常并退出 PHP 进程,以下代码将不起作用。
请尝试在您的代码中添加 try catch 语句,E.G.
try {
$blob = $tableRestProxy->getBlob("mycontainer", "myblobname");
return 'exists';
} catch (ServiceException $e) {
return 'not exists';
}