GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support the delimiter parameter and prefixes result field for bucket listing · Issue #692 · googleapis/google-cloud-java

Support the delimiter parameter and prefixes result field for bucket listing #692

New issue
Copy link
New issue
Copy link
Closed
#726
Closed
Support the delimiter parameter and prefixes result field for bucket listing#692
#726
Copy link
Assignees
mziccard
Labels
api: storageIssues related to the Cloud Storage API.

Description

@dimo414
dimo414
opened on Mar 1, 2016
Issue body actions

See delimiter - this is necessary to be able to list "directories".

In addition to BlobListOption.delimiter(String) it'd be nice if there were an argument-less method that uses / as the delimiter, since that's what ~99% of usages will want. I'd suggest directories() as that method name, so users can write bucket.list("...", BlobListOption.directories()).

Activity

Next
  1. dimo414 commented on Mar 1, 2016

    @dimo414
    dimo414
    on Mar 1, 2016
    Author
    More actions

    Actually, I just realized this is what BlobListOption.recursive() (which is, imo, not a very clear name) is supposed to do. However that method treats the delimiter argument as a boolean; instead it should be passing in /. As is, I don't think it does anything meaningful. Given that the method is broken, I'd vote to rename it directories() which I think more clearly conveys its intent.

  2. mziccard commented on Mar 1, 2016

    @mziccard
    mziccard
    on Mar 1, 2016
    Contributor
    More actions

    Hi @dimo414, thanks again for your feedback.
    You can set the delimiter through Storage's global options:

    StorageOptions options = StorageOptions.builder().pathDelimiter("/").build();

    By default "/" is used.
    When you use BlobListOption.recursive(true) we take care of setting the delimiter option to the pathDelimiter you specified when you created the StorageOptions.

    I agree that the option's name is counter-intuitive. In fact when set to BlobListOption.recursive(true) it does NOT list the content of subdirectories. We should probably make it such that BlobListOption.recursive(false) sets the delimiter option, or change the name. /cc @aozarov

  3. dimo414 commented on Mar 1, 2016

    @dimo414
    dimo414
    on Mar 1, 2016
    Author
    More actions

    Playing around with the API Explorer on the list doc page, I see my issue. I am trying to list "directories" which I now see are returned by the API in the prefixes field, not as part of the items field. I don't see a way to get the prefixes (unless, of course, I'm missing something):

    Without a delimiter:

    GET https://www.googleapis.com/storage/v1/b/my-bucket/o?prefix=dir%2F&fields=items%2Fname%2Ckind%2Cprefixes&key={YOUR_API_KEY}
    {
     "kind": "storage#objects",
     "items": [
      {
       "name": "dir/1/foo"
      },
      {
       "name": "dir/2/bar"
      }
     ]
    }
    

    With delimiter /:

    GET https://www.googleapis.com/storage/v1/b/my-bucket/o?delimiter=%2F&prefix=dir%2F&fields=items%2Fname%2Ckind%2Cprefixes&key={YOUR_API_KEY}
    {
     "kind": "storage#objects",
     "prefixes": [
      "dir/1/",
      "dir/2/"
     ]
    }
    

    Is there a way to get dir/1/ and dir/2/ back via the gcloud-java API?

    I'd agree changing the name of BlobListOption.recursive() would be helpful; it's totally unclear what it does presently.

  4. aozarov commented on Mar 1, 2016

    @aozarov
    aozarov
    on Mar 1, 2016
    Contributor
    More actions

    Given that the method is broken, I'd vote to rename it directories() which I think more clearly conveys its intent.

    Yes, I think we got it wrong here, and instead it should set the DELIMITER when "recursive" is false.

    I am fine with renaming (the name now is consistent with the appengine_gcs_client),
    however I don't think directories is a better name (especially because, as @dimo414 mentioned,
    we only return blobs and don't have a notion of "directories").

    Honestly, I am not sure we should add a notion of a directory in this layer (as such notion does not really exists in the underlying service) and string prefixes is a strange beast. Emulating directories is included, ,for example, in the nio contrib. I am open for suggestions though.

  5. dimo414 commented on Mar 1, 2016

    @dimo414
    dimo414
    on Mar 1, 2016
    Author
    More actions

    You're right, directories() doesn't make sense now that I understand what it's actually doing. But there's an abstraction issue with calling it recursive() either - it's not actually "recursing" anything unless you pretend it's recursing over a directory structure, and if you pretend there's a directory structure it makes sense to want to have a notion of a directory :)

    I do think exposing the prefixes field the API returns in some way would be helpful (I, at least, need it in order to display what sets of files are available to the user). Could it just be another method on Page?

  6. aozarov commented on Mar 2, 2016

    @aozarov
    aozarov
    on Mar 2, 2016
    Contributor
    More actions

    Yes, we could change blob listing to return a subclass of Page that also has an accessor for prefixes.
    However, that is not going to play very great with iterateAll (maybe we can live with that).

    Another, more "extreme" option, would be to create a Blob instance also for prefixes with no other
    values than their name (suffixed with the delimiter) and their bucket.

    Thoughts? @dimo414 @mziccard @BrandonY

  7. dimo414
    changed the title [-]Support the delimiter parameter for bucket listing[/-] [+]Support the delimiter parameter and prefixes result field for bucket listing[/+] on Mar 2, 2016
  8. dimo414 commented on Mar 2, 2016

    @dimo414
    dimo414
    on Mar 2, 2016
    Author
    More actions

    Here's my workaround until there's a way to access the prefixes field; hopefully this demonstrates why it would be beneficial - without that field it's an O(objects) operation to compute the "subdirectories" in a "directory".

    public static List<String> directories(Bucket bucket, String prefix) {
        checkArgument(prefix.endsWith("/"), "Prefix must end with a '/', was '%s'", prefix);
        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        Iterator<Blob> iter = bucket.list(BlobListOption.prefix(prefix)).iterateAll();
        while (iter.hasNext()) {
            String path = iter.next().name();
            String tail = path.replaceFirst("^" + prefix, "");
            int nextSlash = tail.indexOf('/');
            builder.add(nextSlash == -1 ? tail : tail.substring(0, nextSlash));
        }
        return builder.build().asList();
    }
    
  9. mziccard commented on Mar 2, 2016

    @mziccard
    mziccard
    on Mar 2, 2016
    Contributor
    More actions

    Yes, we could change blob listing to return a subclass of Page that also has an accessor for prefixes. However, that is not going to play very great with iterateAll (maybe we can live with that).

    This could be a way of doing that but the behavior of iterateAll becomes a bit unexpected. Also I did a check with both prefix and maxResults options set, what happens is that the sizes of prefixes and items JSON arrays always sum up to maxResults (except for the last page) which makes me think they should be iterated as a whole.

    Another, more "extreme" option, would be to create a Blob instance also for prefixes with no other
    values than their name (suffixed with the delimiter) and their bucket.

    This would be a good option but what happens if we then call delete, update or some other method on the prefix blob?

  10. BrandonY commented on Mar 2, 2016

    @BrandonY
    BrandonY
    on Mar 2, 2016
    More actions

    I lean towards leaving the List() call ignorant of delimiters, since they're a fairly uncommon use case outside of building user interfaces and otherwise exploring bucket structure. It does seem reasonable to expose the functionality, though, so perhaps introduce a ListDirectory-type method that assumes a '/' delimiter and returns either a Page structure or an Iterator (where ListEntry contains either a Directory or a Blob).

  11. dimo414 commented on Mar 2, 2016

    @dimo414
    dimo414
    on Mar 2, 2016
    Author
    More actions

    But the list() call is already aware of delimiters via the .recursive() option. Unfortunately it's only half-aware, you can list objects but not directories.

  12. aozarov commented on Mar 2, 2016

    @aozarov
    aozarov
    on Mar 2, 2016
    Contributor
    More actions

    This would be a good option but what happens if we then call delete, update or some other method on the prefix blob?

    API will treat it as any other blob, so delete is likely to return false, get would return null,...
    If using a delimiter is a non common option, maybe a doc on its settings (see bellow) would be sufficient.

    If we think that it is uncommon then I suggest to remove delimiter from the storage options, remove "recursive" (which would be the default mode) and replace it with an explicit option for using the "non-recursive" option, I would actually call it delimiter (like the underlying API) or something more explicit such as simulateDirectories (and document that in this case directories are simulated as a Blob with only name, suffixed with the delimiter, and buckets are populated). Because of being explicit and because with think that this is not going to be a common setting I think that should be enough.

  13. mziccard commented on Mar 2, 2016

    @mziccard
    mziccard
    on Mar 2, 2016
    Contributor
    More actions

    API will treat it as any other blob, so delete is likely to return false, get would return null,...

    Yes my doubt was in fact that this might be confusing as we have no way to distinguish between blobs and directories other than the delimiter suffix. If you think that documenting this is enough (I agree since it seems to be an uncommon usage) then we can go with the solution you propose. I'll take care of this change.

  14. aozarov commented on Mar 2, 2016

    @aozarov
    aozarov
    on Mar 2, 2016
    Contributor
    More actions

    Yes, that would be my vote. @mziccard I take it that is your vote too?

    Summary of my reasoning:

    1. Not a common setting.
    2. Explicit and therefore could be well documented setting to enable this mode/behavior.

    Do you think otherwise or have a different proposal @dimo414 @BrandonY ?

  15. aozarov
    added
    api: storageIssues related to the Cloud Storage API.
    on Mar 2, 2016
  16. 30 remaining items

  17. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore: change waiting condition for the test (#704)

    This issue will close once commit 97e6113 is merged into the 'main' branch.
    97e6113
  18. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore(main): release 0.122.14 (#692)

    c278793
  19. chingor13
    added a commit that references this issue on Jan 22, 2026

    deps: update dependency org.graalvm.buildtools:native-maven-plugin to…

    4c49614
  20. chingor13
    added 2 commits that reference this issue on Feb 24, 2026

    fix: Resolve race condition reported in #692 (#1031)

    87a6606

    chore(main): release 1.12.1 (#1059)

    382e96a
  21. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore: change waiting condition for the test (googleapis#704)

    This issue will close once commit 1512b0f is merged into the 'main' branch.
    1512b0f
  22. chingor13
    added 2 commits that reference this issue on Mar 12, 2026

    fix: Resolve race condition reported in #692 (#1031)

    0e13eb2

    chore(main): release 1.12.1 (#1059)

    15aec27
  23. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v24.…

    d580afb
  24. suztomo
    added a commit that references this issue on Mar 30, 2026

    build: remove reporting section in favor of the config from shared-co…

    96cc5b5
  25. lqiu96
    added a commit that references this issue on Apr 1, 2026

    build: remove reporting section in favor of the config from shared-co…

    5352201
  26. meltsufin
    added 4 commits that reference this issue on Apr 29, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    1ba00a2

    chore: release 1.113.1 (#693)

    6e5e6d6

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    091c49b

    chore: release 1.113.1 (#693)

    dd061bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.