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;
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.toastCadastro();
}
function that captures camera photo
takePicture(){
this.camera.getPicture({
quality : 100,
destinationType : this.camera.DestinationType.DATA_URL,
sourceType : this.camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: this.camera.EncodingType.PNG,
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
uploadPhoto(){
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;
console.log(this.myPhotoURL)
this.cliente.foto = savedPicture.downloadURL;
console.log(this.cliente.foto);
console.log("SAVED " +savedPicture.downloadURL);
});
}