azure - 获取容器内子目录中的所有 blob

标签 azure azure-storage azure-blob-storage

因此,我在将 Blob 放入容器内时遇到问题 - 我能够成功获取容器内的所有 Blob,但不能获取容器中的文件夹内的 Blob - 我怎样才能成功做到这一点?

问题:
我的容器内有一个名为“big/”的文件夹 - 我如何能够从该文件夹中获取所有 blob,而不是像下面所做的那样仅获取通用容器?

所有帮助将不胜感激!

这是我拥有的 getBlobs() 方法(查看下面的图像和代码):
enter image description here

/**
 * Get all blobs from container
 *
 * @param int $max
 * @return array
 */
public function getBlobs(int $max = 5000) : array
{
    // Check if a container is set
    if (!$this->containerName) {
        return [];
    }

    try {
        $blobMeta = [];
        $blobOptions = new ListBlobsOptions();

        // Set the max results at 5000 (Default: 5000)
        $blobOptions->setMaxResults($max);

        do {
            // Grab the defined container
            $blob_list = $this->connect()->listBlobs(
                $this->containerName,
                $blobOptions
            );

            var_dump($blob_list);
            die();

            // Loop through all the
            foreach ($blob_list->getBlobs() as $blob) {
                $blobMeta[] = [
                    'name' => $blob->getName(),
                    'url' => $blob->getUrl(),
                ];
            }
            $blobOptions->setContinuationToken($blob_list->getContinuationToken());

        } while ($blob_list->getContinuationToken());

        return $blobMeta;
    } catch (ServiceException $e) {
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code . ": " . $error_message . PHP_EOL;
        return [];
    }
}

最佳答案

如果要列出文件夹下的 Blob,可以使用 ListBlobsOptionssetPrefix("YourFolderName/") 来执行此操作。您可以在第 430 行 herelistBlobsSample 函数中找到详细的代码示例。 .

关于azure - 获取容器内子目录中的所有 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64594733/

相关文章:

Azure 备份与快照

azure - 如何将一个订阅下的一个 azure 租户(帐户)keyvault 中的 key 共享到另一订阅中的另一个 azure 租户(帐户)keyvault

azure - 获取 Azure Active Directory 的对象总数

c# - SQL Azure 的限制不是搬起石头砸自己的脚吗?

debugging - 如何查看Azure fastCGI上的实际错误?

azure - 如何在本地计算机上模拟Azure文件存储?

c# - 诊断更新 Azure 表的 C# 程序中的内存泄漏的策略

azure - 我可以在同一个 Azure 容器上创建和添加多少个访问策略?

azure - Azure 服务错误对象的文档

c# - 无法批量加载。文件 "csv"不存在或您没有文件访问权限 - Azure