Hi everyone,
I can not display the downloaded images.
1 - I take a photo that is stored on firebase. The image is stored in a folder that has the ID of the connected user as the name.
2 - I try to display these images by clicking a button:
providers / image / image.ts
uploadImage (image: string, userId: string): any {
let storageRef = firebase.storage (). ref ();
let imageName = this.generateUUID ();
let imageRef = storageRef.child (`$ {userId} / $ {imageName} .jpg`);
return imageRef.putString (image, 'data_url');
}
getImage (userId: string, imageId: string): any {
let storageRef = firebase.storage (). ref ();
let imageRef = storageRef.child (`$ {userId} / $ {imageId}`);
return imageRef.getDownloadURL ();
}
private generateUUID (): string {
function s4 () {
return Math.floor ((1 + Math.random ()) * 0x10000)
.toString (16)
.Substring (1);
}
return s4 () + s4 () + '-' + s4 () + '-' + s4 () + '-' +
s4 () + '-' + s4 () + s4 () + s4 ();
}
pages / docs / docs.ts
private images = [];
imageUrls = [];
cameraOptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
constructor (
public navParams: NavParams,
private afAuth: AngularFireAuth,
private camera: Camera,
private imageSrv: ImageProvider,
) {
let data = localStorage.getItem ('images');
if (data) {
this.images = JSON.parse (data);
}
}
takePicture () {
this.camera.getPicture (this.cameraOptions)
.then (data => {
let base64Image = 'data: image / jpeg; base64,' + data;
return this.imageSrv.uploadImage (base64Image, this.afAuth.auth.currentUser.uid);
})
.then (data => {
this.images.push (data.a.name);
localStorage.setItem ('images', JSON.stringify (this.images));
this.downloadImageUrls ();
});
}
downloadImageUrls () {
let promiseList = [];
for (let i = 0; i <this.images.length; i ++) {
let promise = this.imageSrv.getImage (this.afAuth.auth.currentUser.uid, this.images [i]);
promiseList.push (promised);
}
Promise.all (promiseList)
.then (urls => {
this.imageUrls = urls;
console.log (URLs);
});
}
Thank you for your help.
sam