Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. export class Input {
  2. file: File;
  3. name: string;
  4. }
  5.  
  6. <div class="custom-file align-self-center">
  7. <input type="file" class="custom-file-input" id="porfolioImage" accept="image/*, video/*" (change)="handleFileInput($event.target.files, 'porfolioImage')">
  8. <label class="custom-file-label" for="porfolioImage"> {{ placeholder1 }} </label>
  9. </div>
  10.  
  11. export class AdminFrontComponent implements OnInit {
  12.  
  13. task: AngularFireUploadTask;
  14.  
  15. files: Input[] = [];
  16.  
  17. percentage: Observable<number>;
  18.  
  19. handleFileInput(files: FileList, event: string) {
  20. const firstFile = files.item(0);
  21. this.files.push({ file: firstFile, name: event});
  22. }
  23.  
  24. constructor(private storage: AngularFireStorage, private db: AngularFirestore) { }
  25.  
  26. startUpload(name: string, color: string) {
  27. for (let i = 0; i < this.files.length; i++) {
  28. const file = this.files[i].file;
  29.  
  30. const path = `${new Date().getTime()}_${file.name}`;
  31.  
  32. this.task = this.storage.upload(path, file);
  33.  
  34. this.percentage = this.task.percentageChanges();
  35.  
  36. this.task.snapshotChanges().pipe(
  37. finalize(() => {
  38. this.db.collection('entries').doc(name).set( { name, header: color} );
  39. (this.task).task.snapshot.ref.getDownloadURL().then(url => {
  40. const field = this.files[i].name;
  41. const img = {};
  42. img[field] = url;
  43. this.db.collection('entries').doc(name).update(img);
  44. });
  45. })
  46. ).subscribe();
  47. }
  48. }
  49.  
  50. ...
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement