How to get a list of all files in Cloud Storage in a Firebase app?

后端 未结 19 1376
傲寒
傲寒 2020-11-21 11:25

I\'m working on uploading images, everything works great, but I have 100 pictures and I would like to show all of them in my View, as I get the complete list of

19条回答
  •  失恋的感觉
    2020-11-21 12:01

    Combining some answers from this post and also from here, and after some personal research, for NodeJS with typescript I managed to accomplish this by using firebase-admin:

    import * as admin from 'firebase-admin';
    const getFileNames = (folderName: any) => {
      admin.storage().bucket().getFiles(autoPaginate: false).then(([files]: any) => {
        const fileNames = files.map((file: any) => file.name);
        return fileNames;
      })
     }
    

    In my case I also needed to get all the files from a specific folder from firebase storage. According to google storage the folders don't exists but are rather a naming conventions. Anyway I managed to to this by adding { prefix: ${folderName}, autoPaginate: false } the the getFiles function so:

    getFiles({ prefix: `${folderName}`, autoPaginate: false })
    

提交回复
热议问题