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

257
Views
How to upload an image in firebase version 9?

I'm trying to update the version 8 code to version 9, but the image that is uploaded yields Error loading preview ...

Here is the code:

async storeImage(img: { uri: string; base64: string }, userId: string) {
    try {
      let imageUrl = null;
      const imageName = img.uri.substring(img.uri.length - 40);

      const imageRef = ref(this.storage, `profile-images/${userId}/${imageName}`);


      uploadString(imageRef, img.base64, 'base64', { contentType: "image/jpg" }).then((snapshot) => {
        console.log("image stored", snapshot);
      })

      getDownloadURL(ref(this.storage, `profile-images/${userId}/${imageName}`))
        .then(url => {
          const xhr = new XMLHttpRequest();
          xhr.responseType = 'blob';
          xhr.onload = (event) => {
            const blob = xhr.response;
          };
          xhr.open('GET', url);
          xhr.send();
          console.log('getDownloadURL', url);

          imageUrl = url;
        })

      return imageUrl
    } catch (error) {
      console.log(error);
    }
  }
}

The uri string is the address on the device, the base64 is /9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAyKADAAQAAAABAAAAhAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZ...

This is the url from the firebase storage preview.

This is the downloaded url, which should be the same as the above.

I tried also in uploadString to use base64url but nothing.

Any kind of help would be appreciated.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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!