Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of files in a Google Cloud Storage folder using Node.js?

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 files in a particular folder.

The documentation is not clear on how to just get the files from a folder. Apparently it is possible to limit the results with a GetFilesRequest but none of the options include a path or a folder, at least not explicitly.

like image 557
Pier Avatar asked Apr 06 '18 03:04

Pier


People also ask

Does Google Cloud support NodeJS?

Google Cloud lets you choose the best environment to run your Node. js applications, with options for serverless, Kubernetes, VMs, or custom hardware.

What is cloud filestore in GCP?

Google Cloud Filestore, recently launched into Beta, is a managed file service for your apps. This session provides a product overview, features, pricing, and common use cases. We culminate with a demo integration with other GCP services showing an.


1 Answers

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);
  });
};

Now it's finally available on documentation (thanks @Wajahath for the update): https://googleapis.dev/nodejs/storage/latest/Bucket.html#getFiles

like image 157
lyha Avatar answered Sep 17 '22 22:09

lyha