I would like to save image in Storage and database Firebase with ionic , but I don’t to save in this page I get Image data I have takePicure that get image and uploadInformation that send datas to service help someone my code bellow takeImage.ts
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/jpeg;base64,' + imageDate;
this.photo = base64image;
// this.userService.uploadToStorage(this.user.user_id, this.photo, 'citizens')
this.uploadInformation(this.photo);
console.log(this.photo)
}, (error) => {
console.log(error)
})
.catch((error) => {
console.log(error)
})
}
uploadInformation(info) {
let upload = this.userService.uploadToStorage(info);
upload.then().then(res => {
this.userService.storeInfoToDatabase(this.user.key, res.metadata)
.then(() => {
alert('Inserido com sucesso so colocar o toast depois')
})
})
}
Now in my service I have this code and the storeInfoToDatabase method received 2 parameters user.key and image name service.ts
uploadToStorage(information: any): AngularFireUploadTask {
let newName = information +'.png';
return this.afs.ref(`users/citizens/${newName}`).putString(information, 'base64');
}
storeInfoToDatabase(user_id, metainfo) {
let toSAve = {
url: metainfo.downloadURLs[0],
fullPath: metainfo.fullPath,
contentType: metainfo.contentType,
}
return this.db.list(`${this.PATH}/citizens`).update(user_id, (toSAve))
}