Trying to implement an upload button using Angular 5, I have the following code in my .ts file:
handleFiles(e) {
this.file = e.srcElement.files[0];
if (this.file.size > 2097152) {
let snackBarRef = this.snackBar.open('Images must be 2 MB or less', 'OK!', {
duration: 3000
});
} else {
this.uploadImage();
}
}
uploadImage() {
let storageRef = firebase.storage().ref();
let path = Date.now().toString() + '-' + this.file.name;
let iRef = storageRef.child('posts/' + path);
let me = this;
iRef.put(this.file).then((snapshot) => {
let snackBarRef = this.snackBar.open('Image uploaded', 'OK!', {
duration: 3000
});
this.storageRef.child('posts/' + path).getDownloadURL().then(function(url) {
me.imageUrl = url;
me.newThumbnail = url;
});
});
}
The console displayed the error: Error: Uncaught (in promise): [object Object].
If you have any suggestions on how to resolve this issue, please share as I haven't been able to find anything during debugging.