Using bucket.getFiles()
it is possible to get all the files in a bucket.
My bucket has thousands of files and I really only want to get metadata on the
Google cloud storage doesn't have folders/sub directories. It is an illusion on top of the flat namespace. i.e what you see as sub directories are actually objects which has a "/" character in its name.
You can read more about how Google cloud storage subdirectories work at the following link https://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork
So by setting the prefix
parameter of GetFilesRequest
to the sub directory name you are interested in will return the object you are looking for.
There is an ability to specify a prefix of the required path in options, e.g.
async function readFiles () {
const [files] = await bucket.getFiles({ prefix: 'users/user42'});
console.log('Files:');
files.forEach(file => {
console.log(file.name);
});
};
This example is the last here: https://cloud.google.com/nodejs/docs/reference/storage/2.3.x/Bucket#getFiles
It's sad that there is so little information about possible options for methods. Hope documenting team will change it soon.