Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda