Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...