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

262
Views
How do I upload multiple files to Firebase from React and get the file name?

I'm trying to set up React with Firebase. Currently i have an input form, where i can upload pictures to my firebase. My issue is that i can't;

  1. Upload more than one file (the new overwrites the old one)
  2. I can't get the files name.
import { getStorage, ref, uploadBytes, } from "firebase/storage";
import { app } from './base'

function SubmitApp (){


    const onChange = (e) => {
        const file = e.target.files[0]
        const storage = getStorage(app)
        const storageRef = ref(storage, 'images') // this names the files images, but can't delete
        uploadBytes(storageRef, file).then(() => {
            console.log('Uploaded to Firebase')
        })
    }
        

    return (
        <form onChange={onChange} >
             <input  type='file' name='file' />
             <button>Submit</button>
        </form>

       
    )
}

export default SubmitApp
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To upload all files:

const onChange = (e) => {
  const storage = getStorage(app)
  const storageRef = ref(storage, 'images')
  const now = Date.now()
  e.target.files.forEach((file, index) => {
    uploadBytes(storageRef.child("file_"+now+"_"+index), file).then(() => {
      console.log('Uploaded to Firebase')
    })
  })
}

Here we loop over all files the user selected, and name them after the current time and their index on the server.

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!