【发布时间】:2018-03-14 18:52:32
【问题描述】:
我试图找出一个 blob 是否存在。当 blob 不存在时,我的 try-catch 和 Azure 的 ServiceException 根本不会被捕获。我尝试按照here 的步骤进行操作。
public function checkBlobExists($path) {
$container = config('azure.storage.container');
$blobClient = ServicesBuilder::getInstance()->createBlobService(config('azure.storage.connection_string'));
try {
$blob = $blobClient->getBlob($container, $path);
return true;
} catch (ServiceException $e) {
return false;
}
return false;
}
这是一些错误堆栈:
ServiceException in ServiceRestProxy.php line 491:
Fail:
Code: 404
Value: The specified blob does not exist.
details (if any): .
in ServiceRestProxy.php line 491
at ServiceRestProxy::throwIfError(object(Response), array('200', '206')) in ServiceRestProxy.php line 409
at ServiceRestProxy->MicrosoftAzure\Storage\Common\Internal\{closure}(object(ClientException)) in Promise.php line 203
【问题讨论】:
-
离题评论 .... 恕我直言
getBlob在下载 blob 时检查 blob 是否存在可能是一项非常昂贵的操作。为什么不用getBlobProperties这个轻量级的操作呢? -
@GauravMantri 我最终使用了
getBlobProperties。好点子。