Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda