0

I see that the .NET examples have a ListContainersSegmented API call.

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. Is there a different way to obtain the NextMarker or ContinuationToken for this call?

Somansh Reddy
  • 125
  • 2
  • 13

2 Answers2

2

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. 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());
            }

        }

enter image description here

Jim Xu
  • 21,610
  • 2
  • 19
  • 39
0

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);
Somansh Reddy
  • 125
  • 2
  • 13