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

后端 未结 19 992
傲寒
傲寒 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:02

    For node js, I used this code

    const Storage = require('@google-cloud/storage');
    const storage = new Storage({projectId: 'PROJECT_ID', keyFilename: 'D:\\keyFileName.json'});
    const bucket = storage.bucket('project.appspot.com'); //gs://project.appspot.com
    bucket.getFiles().then(results => {
        const files = results[0];
        console.log('Total files:', files.length);
        files.forEach(file => {
          file.download({destination: `D:\\${file}`}).catch(error => console.log('Error: ', error))
        });
    }).catch(err => {
        console.error('ERROR:', err);
      });
    

提交回复
热议问题