0

I am using the nodeJS google storage module to get files from a bucket, but the bucket contains loads of files and folders so it is taking a very long time to return , any suggestion on how to make it faster? or more stream line?

this is my code

export const getFiles = async () => {
    const BUCKET_NAME = 'archive';  
    const bucket = new Storage({credentials: creds}).bucket(BUCKET_NAME);
    const [ bucketFiles ] = await bucket.getFiles({autoPaginate: false});
    console.log(bucketFiles)
  

    return bucket
    .getFiles()
    .then(([files]) => {
      const filesResponse = files.map(({ metadata: file }) => ({
        cacheControl: file.cacheControl || "",
        contentEncoding: file.contentEncoding || "",
        contentType: file.contentType || "",
        version: file.generation,
        id: file.id,
        downloadLink: file.mediaLink,
        path: file.name,
        size: file.size,
        updated: file.updated,
        originalFileName: file.originalFileName,
      
      }));
      console.log ({ bucket: bucket.name, files: filesResponse });
      return ({ bucket: bucket.name, files: filesResponse });
    })
    .catch();
};
  • Can you confirm to us whether you want to return all files from the bucket or any specific files. Meanwhile you can check with these Stackoverflow [Link1](https://stackoverflow.com/questions/53288478/listing-files-in-google-cloud-bucket-with-thousands-of-files) and [Link2](https://stackoverflow.com/questions/49684942/how-to-get-a-list-of-files-in-a-google-cloud-storage-folder-using-node-js) which might be helpful. – Sandeep Vokkareni Dec 01 '22 at 10:42
  • All the files, I am checking the links now – Adam Barnett Dec 02 '22 at 11:01
  • I don’t think you can do any faster way than this which is stated in the [documentation](https://cloud.google.com/storage/docs/listing-objects#list-objects). – Sandeep Vokkareni Dec 05 '22 at 14:50

0 Answers0