Guest User

Untitled

a guest
Mar 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. startUpload(event: FileList) {
  2. // The File object
  3. const file = event.item(0)
  4.  
  5. // Client-side validation example
  6. if (file.type.split('/')[0] !== 'image') {
  7. console.error('unsupported file type :( ')
  8. return;
  9. }
  10.  
  11. // The storage path
  12. const path = `images/avatars/${new Date().getTime()}_${file.name}`;
  13.  
  14. // Totally optional metadata
  15. const customMetadata = { app: 'My AngularFire-powered PWA!' };
  16. // The main task
  17. let afd = this.afd;
  18. this.task = this.storage.upload(path, file, { customMetadata })
  19. let url = this.task.downloadURL();
  20. this.aFAuth.authState.subscribe(auth => {
  21. afd.object(`/profile/${auth && auth.email && auth.uid}`).update({path: path , downloadURL: url })
  22. })
  23. // Progress monitoring
  24. this.percentage = this.task.percentageChanges();
  25. this.snapshot = this.task.snapshotChanges();
  26.  
  27. // The file's download URL
  28. this.downloadURL = this.task.downloadURL();
  29. //Realtime showing
  30. this.snapshot = this.task.snapshotChanges().pipe(
  31. tap(snap => {
  32. if (snap.bytesTransferred === snap.totalBytes) {
  33. // Update firestore on completion
  34. this.db.collection('photos').add( { path, size: snap.totalBytes })
  35. }
  36. })
  37. )
  38. //All time showing
  39.  
  40. }
  41.  
  42. let url = this.task.downloadURL();
  43. this.aFAuth.authState.subscribe(auth => {
  44. afd.object(`/profile/${auth && auth.email && auth.uid}`).update({path: path , downloadURL: url })
  45. })
Add Comment
Please, Sign In to add comment