gpt4 book ai didi

php - Windows Azure SDK for PHP 中列出的容器

转载 作者:行者123 更新时间:2023-12-03 01:56:54 25 4
gpt4 key购买 nike

我正在尝试列出容器,但到目前为止一点运气都没有......我已经尝试过

$aBlobContainer = $blobRestProxy->listContainers();

for($i = 0;$i<= count($aBlobContainer); $i++)
{
echo 'Blob Container name is: '.$aBlobContainer[$i]->Name."\n";
}

但是我有错误

无法将 WindowsAzure\Blob\Models\ListContainersResult 类型的对象用作数组

一整天都在尝试解决这个问题,但似乎没有取得任何进展...让我知道我是否在做一些愚蠢的事情,或者是否有更好的方法来查明容器是否已经存在?谢谢!

编辑:

变量 $aBlobContainer 的 var_dump 出现为

    object(WindowsAzure\Blob\Models\ListContainersResult)#42 (5) {      ["_containers":"WindowsAzure\Blob\Models\ListContainersResult":private]=>      array(2) {        [0]=>        object(WindowsAzure\Blob\Models\Container)#48 (4) {          ["_name":"WindowsAzure\Blob\Models\Container":private]=>          string(6) "abc123"          ["_url":"WindowsAzure\Blob\Models\Container":private]=>          string(48) "http://orig.blob.core.windows.net/abc123"          ["_metadata":"WindowsAzure\Blob\Models\Container":private]=>          array(0) {          }          ["_properties":"WindowsAzure\Blob\Models\Container":private]=>          object(WindowsAzure\Blob\Models\ContainerProperties)#47 (2) {            ["_lastModified":"WindowsAzure\Blob\Models\ContainerProperties":private]=>            object(DateTime)#49 (3) {              ["date"]=>              string(19) "2012-11-29 01:32:20"              ["timezone_type"]=>              int(2)              ["timezone"]=>              string(3) "GMT"            }            ["_etag":"WindowsAzure\Blob\Models\ContainerProperties":private]=>            string(19) ""0x8CF9BE88256926F""          }        }        [1]=>        object(WindowsAzure\Blob\Models\Container)#46 (4) {          ["_name":"WindowsAzure\Blob\Models\Container":private]=>          string(8) "multi123"          ["_url":"WindowsAzure\Blob\Models\Container":private]=>          string(50) "http://orig.blob.core.windows.net/multi123"          ["_metadata":"WindowsAzure\Blob\Models\Container":private]=>          array(0) {          }          ["_properties":"WindowsAzure\Blob\Models\Container":private]=>          object(WindowsAzure\Blob\Models\ContainerProperties)#45 (2) {            ["_lastModified":"WindowsAzure\Blob\Models\ContainerProperties":private]=>            object(DateTime)#53 (3) {              ["date"]=>              string(19) "2012-11-29 03:13:16"              ["timezone_type"]=>              int(2)              ["timezone"]=>              string(3) "GMT"            }            ["_etag":"WindowsAzure\Blob\Models\ContainerProperties":private]=>            string(19) ""0x8CF9BF69C25759F""          }        }      }      ["_prefix":"WindowsAzure\Blob\Models\ListContainersResult":private]=>      NULL      ["_marker":"WindowsAzure\Blob\Models\ListContainersResult":private]=>      NULL      ["_nextMarker":"WindowsAzure\Blob\Models\ListContainersResult":private]=>      NULL      ["_maxResults":"WindowsAzure\Blob\Models\ListContainersResult":private]=>      NULL    }

最佳答案

查看Source Code :

$blobContainers = $blobRestProxy->listContainers(); //returns ListContainersResult

为了获取容器列表,您必须执行以下调用:

$blobContainerArray = $blobContainers->getContainers(); //exposes the array of containers

然后您应该能够在 foreachfor 语句中使用该数组。此工作流程与从容器内返回 blob 列表的工作流程相匹配,如 README.md 文件中所示:

try {
// List blobs.
$blob_list = $blobRestProxy->listBlobs("mycontainer");
$blobs = $blob_list->getBlobs();

foreach($blobs as $blob)
{
echo $blob->getName().": ".$blob->getUrl()."<br />";
}
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}

关于php - Windows Azure SDK for PHP 中列出的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13619369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com