Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda