Simple question; how do you check if a blob exists using PHP in Azure blob storage using the file name? I can't seem to find it in the API.
Cheers
Simple question; how do you check if a blob exists using PHP in Azure blob storage using the file name? I can't seem to find it in the API.
Cheers
我今天正在寻找这个,这是最热门的搜索结果,所以想在这里给出我的解决方案,它使用前缀选项仅查找与我正在寻找的名称匹配的 blob。
您还需要包括在内use MicrosoftAzure\Storage\Blob\Models\ListBlobsOptions;
。
function blobExists($name)
{
global $blobClient, $blobContainer;
$listBlobsOptions = new ListBlobsOptions();
$listBlobsOptions->setPrefix($name);
$result = $blobClient->listBlobs($blobContainer, $listBlobsOptions);
return count($result->getBlobs());
}
使用适用于 Azure 的 PHP SDK。
/ Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// Get blob.
$blob = $blobRestProxy->getBlob("mycontainer", "myblob");
if ($blob) {
//blob exists
}
使用 PHP SDK v4.10 的解决方案
$storageClient = $this->azure->get_blob_storage();
//check if blob exists
$exists = $storageClient->blobExists(<container name>, <blob name>);
进入 SDK 文件夹中的 blob.php 以查看 API 函数的完整列表。