Repository navigation
setMaxResults doesn't seem to work for Cloud Storage API #1511
Description
Activity
garrettjonesgoogle commented
on Jan 11, 2017 ContributorMore actionsCould you try using a more recent version? The artifact is now named
and the latest version isgoogle-cloud-java0.8.1.- addedapi: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.
on Jan 11, 2017 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.
Is
google-cloud-javain maven central? I can't seem to find it.garrettjonesgoogle commented
on Jan 13, 2017 ContributorMore actionsOops sorry, the artifact is named
google-cloud.garrettjonesgoogle commented
on Jan 26, 2017 ContributorMore actions@johanhaleby , were you able to try out the new version?
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); } }
@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.
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.
18 remaining items
- added a commit that references this issue
on Sep 16, 2022 - added a commit that references this issue
on Oct 4, 2022 - added a commit that references this issue
on Jan 6, 2026 - added a commit that references this issue
on Jan 22, 2026 - added a commit that references this issue
on Feb 24, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 20, 2026 - added a commit that references this issue
on Mar 23, 2026 - added a commit that references this issue
on Mar 30, 2026 - added a commit that references this issue
on Apr 1, 2026
I'm using:
which transitively depends on
com.google.apis:google-api-services-storage:v1-rev62-1.21.0and I have the following code:However the number of items are still 1000 (which is the default value) regardless of the value I pass to
setMaxResults:This yields 1000 as result.