Created
November 22, 2017 01:26
-
-
Save thegrid22593/f87f2b9736fdf87f7dfb6cee6a120918 to your computer and use it in GitHub Desktop.
Upload files to firebase for angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="file" id="filebutton" value="upload" #filebtn (change)="filebuttoni($event)"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment