白板的微信
2019-06-05 12:43:45
如何在Firebase應(yīng)用程序中獲得云存儲中所有文件的列表?我正在上傳圖片,一切都很好,但我有100張照片,我想在我的View,當(dāng)我在文件夾中獲得圖像的完整列表時(shí),我找不到用于這項(xiàng)工作的任何API。
3 回答

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
附注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); }); }); }); });
添加回答
舉報(bào)
0/150
提交
取消