Upload Image Firebase Ionic 3


#1

I have in my page the following code to get image of camera:

  takePicture() {
    this.photo = '';
    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      allowEdit: true,
      // correctOrientation: false,
      targetWidth: 1000,
      targetHeight: 1000
    }
    this.camera.getPicture(options)
              .then((imageDate) => {
                let base64image = 'data:image/png;base64,' + imageDate;
                this.photo = base64image;
                this.userService.uploadAndSave(this.user.user_id, this.photo, 'citizens')  ////send 3 params to service
              }, (error) => {
                console.log(error)
              })
              .catch((error) => {
                console.log(error)
              })
  }

in this code above, I send 3 parameters to service to save image profile in Firestore and Database
in Firestore I want in this order /users/citizens/…images.png
in Dababase I want users/citizens/image: ‘image…png’

In my service I have the following code:

public uploadAndSave(user_id: string, image: any, path: string) {
  let contact = { user_id: user_id, image: image, url: '', fullPath: '' };
 
    let storageRef = this.fb.storage().ref();  // Pega referência do Storage
    let basePath = `/users/${path}/` + contact.user_id; // A pasta onde será salva a imagem no FireStores
    contact.fullPath = basePath + '/' + contact.image + '.png';  // o nome da imagem será o nome do contato
    let uploadTask = storageRef.child(contact.fullPath).putString(contact.image.fileToUpload, 'base64');  // criar uma task para fazer upload

    uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
    (snapshot) => {
      var progress = (progress.snapshot.bytesTransferred / progress.snapshot.totalBytes) * 100;
      console.log(progress + "% done");
    },
    (error) => {
      console.error(error);
    },
    () => {
      contact.url = uploadTask.snapshot.downloadURL;  // com isso conseguimos exibir a imagem do contato depois
      this.update(contact, 'citizens');
    }); 
}

But I don’t to save image, someone please ?