Skip to content

Storage bucket.getFiles() not including sub-directories when specifying a prefix #514

Description

@drewbryant

GCS supports also returning "sub-directories" (i.e., common object prefixes) when listing a bucket and specifying a prefix (e.g., "/") within the query.

The sub-directories are returned as CommonPrefixes within the response.

Could these be included as well in the bucket.getFiles() response? Or maybe add a flag to specify whether subdirectories should also be returned.

Currently, the only work-around I've come up with is listing all objects within the bucket (expensive) and then filtering the response.

Activity

  1. stephenplusplus commented on Apr 29, 2015

    @stephenplusplus
    Contributor

    Is this in the JSON API? https://cloud.google.com/storage/docs/json_api/v1/buckets/list doesn't seem to show it returning anything other than the objects that match the original prefix.

  2. drewbryant commented on Apr 29, 2015

    @drewbryant
    Author

    Looks like it's in the XML API, but not the JSON API currently:
    https://cloud.google.com/storage/docs/reference-headers#delimiter

  3. ryanseys commented on Apr 29, 2015

    @ryanseys
    Contributor

    It might be the same thing as prefixes available through the JSON API (I'm not familiar with the XML API -- didn't even know one existed before today), in which case it's accessible through the apiResponse object provided in the 4th parameter in the getFiles() call: See here for relevant code. We're sorry it's not directly accessible through the first array of files.

  4. ryanseys commented on Apr 30, 2015

    @ryanseys
    Contributor

    Yes, I believe that is the case. You can access the CommonPrefixes value like so:

    var query = {
      delimiter: '/'
    };
    bucket.getFiles(query, function(err, files, nextQuery, apiResponse) {
      // files is array of files
      // apiResponse.prefixes is the same as CommonPrefixes
    });
  5. drewbryant commented on May 1, 2015

    @drewbryant
    Author

    Great to see that the common prefixes are already coming back in the fourth parameter. I think it's actually better that you keep the prefixes separated from the actual files/objects. Thanks Ryan/Stephen!

  6. ryanseys commented on May 1, 2015

    @ryanseys
    Contributor

    No problem, glad we could help!

  7. HadyZ commented on Apr 15, 2019

    @HadyZ

    Hello I tried to specify the delimiter but nothing change I cannot access a folder ref to read files from , I am using admin sdk

    any help

  8. 23 remaining items

  9. added a commit that references this issue on Feb 3, 2026
  10. added a commit that references this issue on Feb 4, 2026
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