Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

javascript - Firebase promise react native

I need to get list of files from a specific Firebase storage folder. To access the folder I need to run a firebase Realtime database which provides the folder structure.

Structure of firebase nested folder is like this

images/year/month/day/

In the above folder images are stored. I need to list the data with a downloadable url of the files:

images/2020/jan/1/img1.jpg images/2020/jan/2/img1.jpg images/2020/jan/2/img2.jpg images/2020/jan/10/img.jpg images/2020/feb/4/img2.jpg images/2021/jan/2/img2.jpg

My code

firebase.database().ref("images").once("value", (userSnapshot) => {
   userSnapshot.forEach(yr => {
        const year = yr.key;
        yr.forEach(mnth => {
          const month = moment(mnth.key, 'MM').format('MMM');
          const mm = mnth.key;
          mnth.forEach(dy => {
            const day = dy.key;
            dy.forEach(element => {
              // Here I need to call the function to list all the files 
                asynchronously
              // after getting files I need to push this to an array with the following data of year, month, date, files
            });
          });
       });
    });
});

file list function has the following code:

var pref = 'images/'+year+'/'+month+'/'+day+'/'+element+'/';
var listRef = firebase.storage().ref(pref);
res.items.forEach((itemRef) => {
                        
var files = itemRef.name;
                        listRef.child(files).getDownloadURL().then(function(fileurl) {
  const furl = fileurl;
  filelist.push({furl});
}).catch(function(error) {
  // Handle any errors
});
});
})
question from:https://stackoverflow.com/questions/65906115/firebase-promise-react-native

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...