How to list all the files from firebase storage using ReactJS ?
Last Updated :
25 Jul, 2024
To list all the files from Firebase storage using React JS we will access the Firebase storage using the SDK and display the data on the webpage from the storage.
Prerequisites:
Approach:
To list all the files from Firebase storage using ReactJS we will first configure the Firebase storage in the application using the Firebase Storage JavaScript SDK. Then initialize Firebase and access the storage using firebase.storage() method.
Steps to create React Application And Installing Module:
Step 1: Create a React-app using the following command:
npx create-react-app myapp
Step 2: After creating your project folder i.e. myapp, move to it using the following command:
cd myapp
Project Structure:

Step 3: After creating the ReactJS application, Install the firebase module using the following command:
npm i [email protected] --save
The updated dependencies in package.json file.
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"firebase": "^8.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Step 4: Go to your firebase dashboard and create a new project and copy your credentials.
const firebaseConfig = {
apiKey: "your api key",
authDomain: "your credentials",
projectId: "your credentials",
storageBucket: "your credentials",
messagingSenderId: "your credentials",
appId: "your credentials"
};
Step 5: Initialize the Firebase into your project by creating a firebase.js file with the following code.
JavaScript
// Filename - firebase.js
import firebase from 'firebase';
const firebaseConfig = {
// Your Credentials
};
firebase.initializeApp(firebaseConfig);
let storage = firebase.storage();
export default storage;
Step 6: Now go to your storage section in the firebase project and update your security rules. Here we are in testing mode, so we allow both read and write as true. After updating the code shown below, click on publish.Â

Step 7: Now implement the list part. Here, We are going to use a method called listAll which helps us to get the list of all the files from firebase storage.
JavaScript
// Filaname - App.js
import { useState } from "react";
import storage from "./firebase";
function App() {
// States for data and image
const [data, setData] = useState([]);
const [image, setImage] = useState("");
const upload = () => {
if (image == null) return;
// Sending File to Firebase Storage
storage
.ref(`/images/${image.name}`)
.put(image)
.on("state_changed", alert("success"), alert);
};
// List All Files
const listItem = () => {
storage
.ref()
.child("images/")
.listAll()
.then((res) => {
res.items.forEach((item) => {
setData((arr) => [...arr, item.name]);
});
})
.catch((err) => {
alert(err.message);
});
};
return (
<div className="App" style={{ marginTop: 250 }}>
<center>
<input
type="file"
onChange={(e) => {
setImage(e.target.files[0]);
}}
/>
<button onClick={upload}>Upload</button>
<br />
<br />
<br />
<br />
<br />
<br />
<button onClick={listItem}>
List Item
</button>
<br />
<br />
{data.map((val) => (
<h2>{val}</h2>
))}
</center>
</div>
);
}
export default App;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Similar Reads
How to upload files in firebase storage using ReactJS ? Firebase Storage is a powerful cloud storage solution provided by Google's Firebase platform. It allows developers to store and retrieve user-generated content, such as images, videos, and other files, in a secure and scalable manner. In this article, we will explore how to upload files to Firebase
2 min read
How to get meta data of files in firebase storage using ReactJS ? Within the domain of web development, effective file management is a frequent necessity, and Firebase Storage emerges as a resilient solution. This article explores the nuances of extracting metadata from files housed in Firebase Storage through the lens of ReactJS. PrerequisitesNode JS or NPMReact
2 min read
How to delete file from the firebase using file url in node.js ? To delete a file from the Firebase storage we need a reference to store the file in storage. As we only have the file URL we need to create a reference object of the file in Firebase storage and then delete that file. Deleting a file using the file URL can be done in two steps - Get the reference to
2 min read
How to push data into firebase Realtime Database using ReactJS ? Firebase is a popular backend-as-a-service platform that provides various services for building web and mobile applications. One of its key features is the Realtime Database, which allows developers to store and sync data in real-time. In this article, we will explore how to push data into the Fireb
2 min read
How to View All the Uploaded Images in Firebase Storage? In this article, we are going to Load all the images from the Firebase Storage and showing them in the RecyclerView. Normally we show an image after adding a link to the real-time database. Let's say we want to show all the images uploaded as we see in the gallery. We will be just viewing all the im
4 min read