Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
How do I get user details in Firebase Storage?

I'm a new programmer and very new to firebase and I'm trying to get the current user files info to display on the screen, it seems that my problem is that I can get the URL and the metadata separately, how do I combine them? how can I take everything at once? I need to show the file name, date, time, link to download.

const getUserFiles = async () => {
  if (!userUID) {
    return null;
  }
  let listRef = storageRef.child(userUID);
  listRef.listAll().then(res => {
    // res.prefixes.forEach((item) => {
    // });
    res.items.forEach(item => {
      item.getMetadata().then(item => {
        var file = {
          name: item.name.toString(),
          timeCreated: item.timeCreated.toString(),
          link: '',
        };
        myFiles.push(file);
      });
    });
    res.items.forEach(item => {
      let counter = 0;
      item.getDownloadURL().then(url => {
        myFiles[counter].link = url.toString();
      });
    });
  });
  console.log(myFiles);
};

the current method don't work! and notice that the userUID its only the uid without the user (local state)

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is with the asynchronous calls. You're making an async call in forEach and forEach expects a synchronous function.

You can change the logic to use for-of instead.

See below:

const getUserFiles = async () => {
  if (!userUID) {
    return null;
  }

  let listRef = storageRef.child(userUID);

  const res = await listRef.listAll();

  for (const itemRef of res.items) {
    const itemMetadata = await itemRef.getMetadata();
    const url = await itemRef.getDownloadUrl();

    var file = {
      name: itemMetadata.name.toString(),
      timeCreated: itemMetadata.timeCreated.toString(),
      link: url,
    };

    myFiles.push(file);
  }

  console.log(myFiles);

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!