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

247
Visualizações
How to get image filename from Firebase Storage?

I am using the following:

const [allImages, setImages] = useState([]);

 
  const getFromFirebase = () => {
    //1.
    let storageRef = storage.ref(user1);
    //2.
    storageRef.listAll().then(function (res) {
        //3.
        res.items.forEach((imageRef) => {
          console.log(imageRef);
          imageRef.getDownloadURL().then((url) => {
              //4.
              setImages((allImages) => [...allImages, url]);
          });
        });
        
      })
      .catch(function (error) {
        console.log(error);
      });
      console.log(allImages);
  };

and then displaying via:

<button onClick={getFromFirebase}>Show</button><br/><br/>
             <div id="photos">
     {allImages.map((image) => {
        return (
           <div key={image} className="image">
              <img className="uploadedfile" src={image} alt="" />
              <button className="buttondelete" onClick={() => deleteFromFirebase(image)}>
               Delete
              </button>
           </div>

I realise this is returning the getDownloadURL for the image URL, but how do I also return the image filename?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To get the filename you can use getMetadata:

imageRef.getMetadata().then(metadata => {
  // do something with metadata.name
});
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the 'getMetaData' method.

import { getStorage, ref, getMetadata } from "firebase/storage";

// Create a reference to the file whose metadata we want to retrieve
const storage = getStorage();
const forestRef = ref(storage, 'images/forest.jpg');

// Get metadata properties
getMetadata(forestRef)
  .then((metadata) => {
  // Metadata now contains the metadata for 'images/forest.jpg'
})
.catch((error) => {
   // Uh-oh, an error occurred!
});

You can refer Firebase Docs - File Metadata for a better understanding

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