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

291
Visualizações
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 à 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