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

111
Views
React - Upload avatar to firebase

Good afternoon, I can’t figure out how to upload a photo (avatar) to firebase, but so that the avatar for each user is different and saved at each user login. User registration via firebase Authentication

const [user, loading] = useAuthState(auth);
  const [image , setImage] = useState("");
  const storage = getStorage();

//upload function
  const upload = ()=>{
    const storageRef = ref(storage, `usersAvatar/${image.name}`);

    if(image == null) return;
    uploadBytes(storageRef, image).then(() =>{
      getDownloadURL(storageRef).then((url) => {
        setUrl(url);
      })
    })
  }


// return
<input type="file" onChange={(e)=>{setImage(e.target.files[0])}}/>
<button onClick={upload}>Upload</button>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you use this location in Cloud Storage to store the user's image:

const storageRef = ref(storage, `usersAvatar/${image.name}`);

Any user who uploads the same image.name will end up overwriting anyone else's image.

What you'll want to do instead is based the upload location on the UID of the user. So for example:

const storageRef = ref(storage, `usersAvatar/${user.uid}/${image.name}`);
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!