Open In App
Related Articles

How to get meta data of files in firebase storage using ReactJS ?

Improve Article
Save Article
Like Article

The following approach covers how to get metadata of files in firebase storage using react. Metadata is the basic information about the file. We have used the firebase module to achieve so.

Creating React Application And Installing Module:

  • Step 1: Create a React application 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 firebase@8.3.1 --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 firebase.js file with the following code.


import firebase from 'firebase';
const firebaseConfig = {
    // Your Credentials
var 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 meta data part. Here, We are going to use a method called getMetadata which helps us to get the meta data of files in firebase storage.


import { useState } from 'react';
import storage from './firebase';
function App() {
  const [image, setImage] = useState('');
  const [show, setShow] = useState(false);
  const [value, setValue] = useState('');
  const upload = () => {
    if (image == null)
    // Sending File to Firebase Storage
      .on("state_changed", alert("success"), alert, () => {
        // Getting Meta Data Of File
          .then((data) => {
  return (
    <div className="App" style={{ marginTop: 250 }}>
        <input type="file" onChange={(e) => { setImage([0]) }} />
        <button onClick={upload}>Upload</button>
        <br /><br /><br /><br />
          show ?
              <h2>Name : {}</h2>
              <h2>Size : {value.size}</h2>
              <h2>Path : {value.fullpath}</h2>
              <h2>Time : {value.timeCreated}</h2>
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:

Last Updated : 04 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials