简体   繁体   English

如何使用新的 Java v12 SDK 为 Azure Blob 存储检索分段的容器列表?

[英]How to retrieve a segmented List of Containers using the new Java v12 SDK for Azure Blob Storage?

I see that the .NET examples have a ListContainersSegmented API call.我看到 .NET 示例有一个ListContainersSegmented API 调用。

The Java SDK documentation specifies a listBlobContainers call but there is no mention about when it hits the limit of containers it will return per call. Java SDK 文档指定了一个listBlobContainers调用,但没有提及它何时达到每次调用将返回的容器限制。 Is there a different way to obtain the NextMarker or ContinuationToken for this call?是否有其他方法可以获取此调用的NextMarkerContinuationToken

When we use the method listBlobContainers to list containers, It will paginate if its number is greater than 5000. We also can use ListBlobContainersOptions to define per page size.当我们使用listBlobContainers方法列出容器时,如果它的数量大于 5000,它将分页。我们也可以使用ListBlobContainersOptions来定义每页大小。 For more details, please refer to here and here有关更多详细信息,请参阅此处此处

for example例如

String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
        BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
                .endpoint(endpoint)
                .credential(credential)
                .buildClient();
        ListBlobContainersOptions options = new ListBlobContainersOptions();
        options.setMaxResultsPerPage(5);
        PagedIterable<BlobContainerItem> pagedIterableResponse= blobServiceClient.listBlobContainers(options, null);
        Iterator<PagedResponse<BlobContainerItem>> ite = pagedIterableResponse.iterableByPage().iterator();
        int i =1;
        while(ite.hasNext()){
            PagedResponse<BlobContainerItem> items= ite.next();
            System.out.println("The containers in the page "+i);
            i++;
            for (BlobContainerItem item: items.getValue()
                 ) {

                   System.out.println("\t"+item.getName());
            }

        }

在此处输入图像描述

We can use the following method to get the continuation token我们可以使用下面的方法来获取延续令牌

        List<BlobItem> allBlobs = new ArrayList<>();
        String continuationToken;
        ListBlobsOptions options = new ListBlobsOptions().setMaxResultsPerPage(5);
        Iterator<PagedResponse<BlobItem>> response = containerClient.listBlobs(options, Duration.ofSeconds(30)).iterableByPage().iterator();
        do {
            PagedResponse<BlobItem> pagedResponse = response.next();
            List<BlobItem> blobs = pagedResponse.getValue();
            continuationToken = pagedResponse.getContinuationToken();
            blobs.forEach(b -> System.out.println(b.getName()));
            allBlobs.addAll(blobs);
        } while (continuationToken != null);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用新的 Azure 存储 SDK v12 打开可写 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 到新 Blob? - How can I open a writeable stream to a new Blob using the new Azure Storage SDK v12? 使用 Java v12 SDK 在 Azure Blob 存储中复制 Blob - Copy Blob in Azure Blob Storage using Java v12 SDK 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? 使用 spring boot 在 azure 中从 v8 升级到 v12 java sdk 后无法连接到 azure-blob-storage - Unable to connect to azure-blob-storage after upgrading from v8 to v12 java sdk in azure using spring boot Azure Blob 存储 SDK v12 - BlobClient DownloadAsync 消失了吗? - Azure Blob Storage SDK v12 - BlobClient DownloadAsync gone? 如何使用 .NET v12 SDK 在 Azure Blob 存储中使用指定的 ContentType 上传 Blob? - How upload blob in Azure Blob Storage with specified ContentType with .NET v12 SDK? 使用带有 Python V12 SDK 的 BlobServiceClient 将本地文件夹上传到 Azure Blob 存储 - Upload local folder to Azure Blob Storage using BlobServiceClient with Python V12 SDK 使用指定的 ContentType 将 blob 上传到 Azure Blob 存储并同时覆盖(.NET v12 SDK)? - Upload blob into Azure Blob Storage with specified ContentType and overwrite same time (.NET v12 SDK)? 如何使用最新的 Azure SDK .NET API v12 在 Blob 上获取共享访问签名? - How to get a Shared Access Signature on a Blob using the latest Azure SDK .NET API v12? 使用 Azure 下载 Blob Blob 存储客户端库 v12 for .NET - Download blob using Azure Blob storage client library v12 for .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM