deleteImageRef() { let storage = firebase.storage(); let imageRef = storage.refFromURL(this.imageUrl); let me = this; imageRef.delete().then(function() { me.imageUrl = null; }).catch(function(error) { console.log('error', error); }); }
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; }); }); }
return new Promise((resolve, reject) => { firebase.storage() .ref(ref) .getDownloadURL() .then((url) => { resolve(url); }).catch((error) => { switch (error.code) { case "storage/object_not_found": reject("File doesn't exist"); break; case "storage/unauthorized": reject("User doesn't have permission to access the object"); break; case "storage/canceled": reject("User canceled the upload"); break; case "storage/unknown": reject("Unknown error occurred"); break; } }); });