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

290
Vistas
Google Cloud Storage listAll() function not giving output in order

I have some images inside a directory in Google Cloud Storage. I am trying to list all the images inside the directory. The problem is that the files are not consistent in order. Sometimes it will be in order and sometimes not. I want the files in exact order that is displayed on the Google Cloud Platform. How can I do it?

Here is the reference code from documentation:


const storage = getStorage();

// Create a reference under which you want to list
const listRef = ref(storage, 'files/uid');

// Find all the prefixes and items.
listAll(listRef)
  .then((res) => {
    res.prefixes.forEach((folderRef) => {
      // All the prefixes under listRef.
      // You may call listAll() recursively on them.
    });
    res.items.forEach((itemRef) => {
      // All the items under listRef.
    });
  }).catch((error) => {
    // Uh-oh, an error occurred!
  }); 

This is my sample code

var storage = getStorage();

var listRef = ref(storage, "Data");

listAll(listRef)
  .then((res) => {
    res.prefixes.forEach((folderRef) => {});
    res.items.forEach((itemRef) => {
      // All the items under listRef.
      var location = itemRef._location.path_;
      console.log(location);
      getDownloadURL(ref(storage, location))
        .then((url) => {
          console.log(url);
        })
        .catch((error) => {
          console.log(error);
        });
    });
  })
  .catch((error) => {
    // Uh-oh, an error occurred!
    console.log(error);
  });

I want the location and url of the files inside Storage to be in the same order as they are displayed in Storage inside Firebase. But when I reload, they are not consistent in their order. This is the order which I uploaded the files:

This is the order which I uploaded the files

But when I console.log the url, often the order is not the same.

about 4 years ago · Juan Pablo Isaza
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