正在检查Azure blob存储(php)中是否存在blob


Checking if a blob exists in Azure Blob storage (php)

简单问题;如何使用文件名检查Azure blob存储中是否存在使用PHP的blob?我似乎在API中找不到它。

干杯

我今天在找这个,这是最热门的搜索结果,所以我想在这里给出我的解决方案,它使用前缀选项只查找与我要查找的名称匹配的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());
}

使用PHP SDK for Azure。

/ Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// Get blob.
$blob = $blobRestProxy->getBlob("mycontainer", "myblob");
if ($blob) {
   //blob exists
} 

适用于使用PHP SDK v4.10 的解决方案

http://phpazure.codeplex.com/

$storageClient = $this->azure->get_blob_storage();
                    //check if blob exists
        $exists = $storageClient->blobExists(<container name>, <blob name>);

进入SDK文件夹中的blob.php,查看API函数的完整列表。

我发现getBlob接收整个blobe。对于存在测试是更好的

$blobService = BlobRestProxy::createBlobService(.);
$blobService->getBlobMetadata('', $blobPath);

根据Fiddler的说法,它只调用HEAD方法。

我有

"name": "microsoft/azure-storage-blob",
"version": "1.5.4",