How to upload files in firebase storage using ReactJS ?
Last Updated :
26 Jul, 2024
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 Storage using React JS.
Prerequisites
Steps to create React Application And Installing Module
Step 1: Create a React myapp 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: Our project structure will look like this.

Step 3: After creating the ReactJS application, Install the firebase module using the following command:
npm install [email protected] --save
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.
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 create a basic UI and method to upload files to firebase storage.
App.js
import { useState } from 'react';
import storage from './firebase';
function App() {
const [image, setImage] = useState('');
const upload = () => {
if (image == null)
return;
storage.ref(`/images/${image.name}`).put(image)
.on("state_changed", alert("success"), alert);
}
return (
<div className="App">
<center>
<input type="file" onChange={(e) =>
{ setImage(e.target.files[0]) }} />
<button onClick={upload}>Upload</button>
</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:
Here is the image in the firebase storage which we uploaded as shown below:

Similar Reads
How to list all the files from firebase storage using ReactJS ? 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:NPM & Node.jsReact JSFirebaseApproach: To list all the files from Firebase storage using ReactJS we will first configure
3 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 get download link of uploaded files in firebase storage in React JS? Firebase Storage stands out as a robust cloud-based option for housing and distributing user-created content, ranging from images and videos to various files. Within this piece, we'll walk you through the intricate steps of acquiring download links for files that find their way into Firebase Storage
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 send email verification link with firebase using ReactJS? Email verification is a crucial step in user authentication and account security. It ensures that users provide a valid email address and allows you to verify their identity before granting them access to certain features or functionalities. Firebase, a powerful platform for building web and mobile
3 min read
File Uploading In ReactJS File uploading in ReactJS is an important functionality for many web applications, especially those that require user interaction, such as submitting forms, uploading images, or handling documents. In this article, we will walk you through the process of implementing file upload functionality in Rea
5 min read