Skip to content

setMaxResults doesn't seem to work for Cloud Storage API #1511

Description

@johanhaleby

I'm using:

<dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>gcloud-java</artifactId>
            <version>0.2.8</version>
</dependency>

which transitively depends on com.google.apis:google-api-services-storage:v1-rev62-1.21.0 and I have the following code:

Storage storage = ...
storage.objects().list(bucket).setMaxResults((long) Integer.MAX_VALUE).execute().getItems();

However the number of items are still 1000 (which is the default value) regardless of the value I pass to setMaxResults:

System.out.println(storage.objects().list(bucket).setMaxResults((long) Integer.MAX_VALUE).execute().size());

This yields 1000 as result.

Activity

  1. garrettjonesgoogle commented on Jan 11, 2017

    @garrettjonesgoogle
    Contributor

    Could you try using a more recent version? The artifact is now named google-cloud-java and the latest version is 0.8.1.

  2. johanhaleby commented on Jan 11, 2017

    @johanhaleby
    Author

    Oh I was unaware of the change of artifactId, thanks for the hint. I'll try to look into it in a few days if that's ok.

  3. johanhaleby commented on Jan 13, 2017

    @johanhaleby
    Author

    Is google-cloud-java in maven central? I can't seem to find it.

  4. garrettjonesgoogle commented on Jan 13, 2017

    @garrettjonesgoogle
    Contributor

    Oops sorry, the artifact is named google-cloud.

  5. garrettjonesgoogle commented on Jan 26, 2017

    @garrettjonesgoogle
    Contributor

    @johanhaleby , were you able to try out the new version?

  6. self-assigned this
    on Jan 27, 2017
  7. vam-google commented on Jan 31, 2017

    @vam-google
    Contributor

    Looks like it is by design. Though I agree, the API signature, naming and documentation are confusing.
    Apparently Storage.setMaxResults() sets the maximum size for the results page, and the maximum allowed value for it is 1000 (not properly documented).

    As a workaround the following code can be used (it will successfully read > 1000 objects, page by page):

    public class MyStorageExample {
    
      public static void main(String[] args) throws GeneralSecurityException, IOException {
        Storage.Builder sb = new Builder(
            GoogleNetHttpTransport.newTrustedTransport(),
            new JacksonFactory(),
            null);
        Storage storage = sb.build();
    
        Objects objects;
        String pageToken = null;
        final long maxPageSize = 1000L; // 1000 is the maximum possible value
        final String bucketName = "<YOUR_BUCKET_NAME>";
    
        do {
          objects = storage
              .objects()
              .list(bucketName)
              .setMaxResults(maxPageSize)
              .setPageToken(pageToken)
              .execute();
          pageToken = objects.getNextPageToken();
          if(objects.getItems() != null) {
            System.out.println(objects.getItems().size());
          }
        } while (pageToken != null);
      }
    }
  8. johanhaleby commented on Feb 2, 2017

    @johanhaleby
    Author

    @vam-google I'm using something similar to what you're describing. I think it would be nice to improve the docs a bit to make it clear that 1000 is the maximum value.

    Thanks for the support everyone.

  9. vam-google commented on Feb 9, 2017

    @vam-google
    Contributor

    The documentation and default value was updated for the Storage API, and will be available in the never version, once it is released. Closing the issue.

  10. 18 remaining items

  11. added a commit that references this issue on Sep 16, 2022
  12. added a commit that references this issue on Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Sponsor
    SponsoredKunjungi sekarang
    Promo