Skip to content

callback for bucket.getFiles doesn't return prefixes #491

Description

@javorosas

From the docs;

storage > bucket.getFiles > query.delimiter

[...] Objects whose names, aside from the prefix, contain delimiter will have their name truncated after the delimiter, returned in prefixes.

But then there is no reference anywhere to that "prefixes" array (?) that should contain the truncated objects.

This would be really useful if implemented, because as of today, there is not a simple way of making an object browser with folder hierarchy (like the storage explorer in the application console), which is able to list files and folders given a prefix (or inside a folder).

Activity

  1. ryanseys commented on Apr 10, 2015

    @ryanseys
    Contributor

    Related to #342

  2. stephenplusplus commented on Apr 21, 2015

    @stephenplusplus
    Contributor

    Thanks for catching this. The prefixes will be available from the apiResponse (note only will work on master, since #448 was merged):

    bucket.getFiles({ /*...*/ }, function (err, files, nextQuery, apiResponse) {
      // apiResponse.prefixes
    })
  3. added a commit that references this issue on Apr 21, 2015
  4. stephenplusplus commented on Apr 21, 2015

    @stephenplusplus
    Contributor

    We put a more helpful tip in the docs. If you feel we can do better, please re-open!

  5. conet commented on Sep 9, 2019

    @conet

    In the latest version 3.2.1 prefixes can't be obtained because of the wrapping, the callback passed to the getFiles function looks like this:

    cb:(err, results, nextQuery) => {
                if (err) {
                    this.destroy(err);
                    return;
                }
                this._nextQuery = nextQuery;
                if (this._resultsToSend !== Infinity) {
                    results = results.splice(0, this._resultsToSend);
                    this._resultsToSend -= results.length;
                }
                let more = true;
                for (const result of results) {
                    if (this._ended) {
                        break;
                    }
                    more = this.push(result);
                }
                const isFinished = !this._nextQuery || this._resultsToSend < 1;
                const madeMaxCalls = ++this._requestsMade >= this._maxApiCalls;
                if (isFinished || madeMaxCalls) {
                    this.end();
                }
                if (more && !this._ended) {
                    setImmediate(() => this._read());
                }
                this._reading = false;
            }
    

    So this would need a proper change, either a getPrefixes function or a different type of response.

  6. added a commit that references this issue on Sep 15, 2022
  7. 23 remaining items

  8. added a commit that references this issue on Feb 23, 2026
  9. added a commit that references this issue on Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions