亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Firebase應用程序中獲得云存儲中所有文件的列表?

如何在Firebase應用程序中獲得云存儲中所有文件的列表?

白板的微信 2019-06-05 12:43:45
如何在Firebase應用程序中獲得云存儲中所有文件的列表?我正在上傳圖片,一切都很好,但我有100張照片,我想在我的View,當我在文件夾中獲得圖像的完整列表時,我找不到用于這項工作的任何API。
查看完整描述

3 回答

?
繁花如伊

TA貢獻2012條經驗 獲得超12個贊

加上火基云函數以及Firebase與GoogleCloud的更深層次的集成,這已經成為可能。

使用云函數,您可以使用GoogleCloudNode包來完成史詩云存儲操作。下面是一個從CloudStorage獲取所有文件URL到數組中的示例。這個功能每次被保存到Google云存儲時都會被觸發。

附注1這是一個計算上相當昂貴的操作,因為它必須遍歷桶/文件夾中的所有文件。

附注2:我寫這個只是作為一個例子,沒有把很多細節寫成承諾等等。只是想給個主意。

const functions = require('firebase-functions');
const gcs = require('@google-cloud/storage')();

// let's trigger this function with a file upload to google cloud storage

exports.fileUploaded = functions.storage.object().onChange(event => {

  const object = event.data; // the object that was just uploaded
  const bucket = gcs.bucket(object.bucket);
  const signedUrlConfig = { action: 'read', expires: '03-17-2025' }; // this is a signed url configuration object

  var fileURLs = []; // array to hold all file urls 

  // this is just for the sake of this example. Ideally you should get the path from the object that is uploaded :)
  const folderPath = "a/path/you/want/its/folder/size/calculated";

  bucket.getFiles({ prefix: folderPath }, function(err, files) {
    // files = array of file objects
    // not the contents of these files, we're not downloading the files. 

    files.forEach(function(file) {
      file.getSignedUrl(signedUrlConfig, function(err, fileURL) {
        console.log(fileURL);
        fileURLs.push(fileURL);
      });
    });

  });

});

我希望這能給你一個大致的想法。要獲得更好的云功能示例,請查看Google的Gizubrepo充滿了用于FireBase的云功能示例..也檢查他們的GoogleCloudNodeAPI文檔


查看完整回答
反對 回復 2019-06-05
  • 3 回答
  • 0 關注
  • 754 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號