Skip to content

Instantly share code, notes, and snippets.

@adsonrocha
Created May 21, 2017 17:26
Show Gist options
  • Save adsonrocha/5a70284fb49bd6b73bd66a55aa83b23f to your computer and use it in GitHub Desktop.
Save adsonrocha/5a70284fb49bd6b73bd66a55aa83b23f to your computer and use it in GitHub Desktop.
Firebase Storage with AngularFire2
import {Component} from '@angular/core';
import * as firebase from 'firebase';
@Component({
selector: 'my-component',
templateUrl: 'my-component.html'
})
export class FireBaseStorageComponent {
fbStorage: any;
fileName: string;
fileBytes: any;
constructor() {
this.fbStorage = firebase.storage().ref();
}
uploadFile(){
this.fileName: "my-file"; // TODO - get from form input file
let path = this.fbStorage.child('my-storage-path/' + this.fileName);
this.fileBytes = []; // TODO - read from form input file
let uploadTask = path.put(this.fileBytes);
uploadTask.on('state_changed', snapshot => {
//show progress
}, error => {
//do something
}, () => {
//code after complete
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment