uploader.html
<input type="file" id="filebutton" value="upload" #filebtn (change)="filebuttoni($event)">
files.ts
filebuttoni(event) {
let files = event.srcElement.files[0];
let self = this;
let uploader = document.getElementById("uploader");
this.path = "user-profile-pics/"+files.name;
this.storageref = this.storage.child(this.path);
let uploadTask = this.storageref.put(files);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
let progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done!');
switch(snapshot.state) {
case firebase.storage.TaskState.PAUSED:
console.log('upload is paused');
break;
case firebase.storage.TaskState.RUNNING:
console.log('Upload is running');
break;
}
}, function(error) {
switch (error) {
case 'storage/unauthorized':
break;
case 'storage/canceled':
break;
case 'storage/unknown':
break;
}
}, function() {
let downloadURL = uploadTask.snapshot.downloadURL;
console.log('Upload done!');
self.storageref.getDownloadURL().then(url => self.newPhotoURL = url);
});
}