Skip to content

Instantly share code, notes, and snippets.

@thegrid22593
Created November 22, 2017 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegrid22593/f87f2b9736fdf87f7dfb6cee6a120918 to your computer and use it in GitHub Desktop.
Save thegrid22593/f87f2b9736fdf87f7dfb6cee6a120918 to your computer and use it in GitHub Desktop.
Upload files to firebase for angular
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);
});
}
<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