Repository navigation
Storage bucket.getFiles() not including sub-directories when specifying a prefix #514
Description
Activity
- addedapi: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.
on Apr 28, 2015 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.
Looks like it's in the XML API, but not the JSON API currently:
https://cloud.google.com/storage/docs/reference-headers#delimiterIt might be the same thing as
prefixesavailable 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 thegetFiles()call: See here for relevant code. We're sorry it's not directly accessible through the first array of files.Yes, I believe that is the case. You can access the
CommonPrefixesvalue 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 });
Reacted by Martin StaffaGreat 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!
No problem, glad we could help!
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
23 remaining items
- added 3 commits that reference this issue
on Jan 27, 2026 - added a commit that references this issue
on Feb 2, 2026 - added a commit that references this issue
on Feb 3, 2026 - added 2 commits that reference this issue
on Feb 25, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 18, 2026 - added a commit that references this issue
on Mar 27, 2026
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
CommonPrefixeswithin 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.