Ich versuche herauszufinden, ob ein Blob existiert oder nicht. Wenn der Blob nicht existiert, wird mein try-catch
mit Azures ServiceException
überhaupt nicht abgefangen. Ich habe versucht, die Schritte von here zu folgen.Warum kann ich die ServiceException auf dem Azure PHP-SDK nicht abfangen?
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;
}
Dies ist ein Teil des Fehler-Stack:
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
Off topic Kommentar .... IMHO 'getBlob' zur Überprüfung der Existenz des Blobs eine sehr teure Operation sein könnte, wie es den Blob herunterlädt. Warum nicht 'getBlobProperties' verwenden, was eine sehr einfache Operation ist? –
@GauravMantri Ich benutzte schließlich "getBlobProperties". Guter Punkt. – Rail24