Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- startUpload(event: FileList) {
- // The File object
- const file = event.item(0)
- // Client-side validation example
- if (file.type.split('/')[0] !== 'image') {
- console.error('unsupported file type :( ')
- return;
- }
- // The storage path
- const path = `images/avatars/${new Date().getTime()}_${file.name}`;
- // Totally optional metadata
- const customMetadata = { app: 'My AngularFire-powered PWA!' };
- // The main task
- let afd = this.afd;
- this.task = this.storage.upload(path, file, { customMetadata })
- let url = this.task.downloadURL();
- this.aFAuth.authState.subscribe(auth => {
- afd.object(`/profile/${auth && auth.email && auth.uid}`).update({path: path , downloadURL: url })
- })
- // Progress monitoring
- this.percentage = this.task.percentageChanges();
- this.snapshot = this.task.snapshotChanges();
- // The file's download URL
- this.downloadURL = this.task.downloadURL();
- //Realtime showing
- this.snapshot = this.task.snapshotChanges().pipe(
- tap(snap => {
- if (snap.bytesTransferred === snap.totalBytes) {
- // Update firestore on completion
- this.db.collection('photos').add( { path, size: snap.totalBytes })
- }
- })
- )
- //All time showing
- }
- let url = this.task.downloadURL();
- this.aFAuth.authState.subscribe(auth => {
- afd.object(`/profile/${auth && auth.email && auth.uid}`).update({path: path , downloadURL: url })
- })
Add Comment
Please, Sign In to add comment