How to get a Firebase Storage photo URL?

Asked

Viewed 252 times

0

Good morning everyone, I’m having a hard time capturing the URL of a certain photo that is sent to firebase Torage. The client registration works perfectly, the image upload is also done correctly. Then I pass to the client variable.photo receive the myPhotoURL that stores the photo URL, but is not saving in the database, so I will not be able to display the photo later.

  //função do upload de fotos
  private uploadPhoto(): void {
   this.myPhotosRef.child(this.generateUUID()).child('myPhoto.png')
   .putString(this.Picture, 'base64', { contentType: 'image/png' })
   .then((savedPicture) => {
    //aqui a myPhotoURL recebe a URL da foto
    this.myPhotoURL = savedPicture.downloadURL;
  });
 }


//função de cadastro de cliente
adicionarCliente() {
  this.cliente.clienteFinalizado = true;
  this.clienteProvider.adicionarCliente(this.cliente);
  //faz o upload da foto 
  this.uploadPhoto();
  //após upload concluído, a variável foto recebe a URL da foto no storage
  this.cliente.foto  = this.myPhotoURL;
  this.toastCadastro();
 }
  • I am using IONIC3

  • You are saving customer data after changing cliente.foto? Also take into account that putString is asynchronous

  • I made some adjustments in the code, but I still receive Undefined.. Does not return me the URL of the photo registered

  • Place the last two lines of the second function inside a setTimeout of 3s, worked as expected?

  • This code always returns me Undefined, I have done several tests and still could not leave the place, on account of Undefined. I managed to find another code, but return this to me on the console. Firebasestorage.googleapis.com/v0/b/sacola-aplicativo.appspot.com/o/Fotos- Clients%2Ff7d6d5dc-4a07-4627-b2e7%2FmyPhoto.png:1 GET https://firebasestor.googleapis.com/v0/b/sacolala app.appspot.com/o/Customer Photos%2Ff7d6d5dc-4a07-074627- b2e7%2FmyPhoto.png 404 (Not Found)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.