Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!