Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda