How to get the url of a saved image in firebase storage? (Urgent)

I am using a code to capture the camera image, then pass it to a variable, after which send it to the firebase database. But I need to link to the client’s registry, the url of this image, so that at the moment of the query when it is to display the list of clients, I bring the image of each client, that url I will save together in the client’s registry, however I am not getting the url.

I’ve done several tests, and it’s always returning me undefined to the photo url, could someone help me, show me another way to do it, or find the error of my code? This is the first time I use this camera function.

function that adds the client

  adicionarCliente() {
    this.cliente.clienteFinalizado = true;
    //faz o upload da foto 
    //após upload concluído, a variável foto recebe a URL da foto no storage

function that captures camera photo

      quality : 100,
      destinationType :,
      sourceType :,
      allowEdit : true,
      targetWidth: 1000,
      targetHeight: 1000,
      saveToPhotoAlbum: true
    }).then(imageData => {
       // imageData is a base64 encoded string
      this.base64Image = "data:image/jpeg;base64," + imageData;
      //this.Picture is passing the string to our DB
      this.Picture = imageData;
    }, error => {
      console.log("ERROR -> " + JSON.stringify(error));

image upload to firebase

      .putString(this.Picture, 'base64', { contentType: 'image/png' })
      .then((savedPicture) => {
        //aqui a myPhotoURL recebe a URL da foto
        this.myPhotoURL = savedPicture.downloadURL;
        this.cliente.foto = savedPicture.downloadURL;
        console.log("SAVED " +savedPicture.downloadURL);

Which version of Ionic?

Which version of Angular?

Which version of angularfire2?

An example for ionic-angular 3.9.2, Angular 5.0.3, angularfire2 5.0.0-rc.6 and firebase 4.13.1:


<input type="file" accept="image/*;capture=camera" (change)="uploadFile($event)" class="custom-file-input">


import { Component } from '@angular/core';

import { AngularFireStorage, AngularFireUploadTask } from 'angularfire2/storage';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';


  public uploadFile(event) {


    const file =[0];
    const filePath = 'reviews' + '/' + + '/' + this.authService.getUserId();

    const task: AngularFireUploadTask = this.afStorage.upload(filePath, file);

    this.downloadURL = task.downloadURL();
    this.downloadURL.subscribe((url) => {

      // do something 





1 Like

Your example more or less serves me, the problem is this. At the moment of the customer’s registration, either a photo of the camera is captured, or a photo of the gallery is chosen, and this photo has to go next to the client’s registration, ie the idea is to call the upload function of the firebase, and (as I currently do). But there is a variable of mine that is the variable client.foto. This variable should receive the URL for when loading the list, I upload the photo of each respective client.