Created
May 21, 2017 17:26
-
-
Save adsonrocha/5a70284fb49bd6b73bd66a55aa83b23f to your computer and use it in GitHub Desktop.
Firebase Storage with AngularFire2
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
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