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

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

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 Denunciar

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 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