Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { ClasePrueba } from 'src/app/clase-prueba';
  3.  
  4. @Component({
  5. selector: 'app-root',
  6. templateUrl: './app.component.html',
  7. styleUrls: ['./app.component.css']
  8. })
  9.  
  10. export class AppComponent {
  11.  
  12. private downloadLink = document.createElement("a");
  13. private dataAplication = 'data:application/;base64,';
  14. private filebase64 = new ClasePrueba();
  15. private fileName = "";
  16.  
  17. descargarDocumentoBase64() {
  18.  
  19. if (this.filebase64.getBase64().tipoMime == "application/pdf") {
  20. this.fileName = "sample.pdf";
  21. this.showDoc(this.fileName);
  22. }
  23. if (this.filebase64.getBase64().tipoMime == "application/txt") {
  24. this.fileName = "sample.txt";
  25. this.showDoc(this.fileName);
  26. }
  27. if (this.filebase64.getBase64().tipoMime == "application/docx") {
  28. this.fileName = "sample.docx";
  29. this.showDoc(this.fileName);
  30. }
  31.  
  32. }
  33.  
  34. showDoc(fileName) {
  35.  
  36. const linkSource = this.dataAplication + this.filebase64.getBase64().documento;
  37.  
  38. this.downloadLink.href = linkSource;
  39. this.downloadLink.download = fileName;
  40. this.downloadLink.click();
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement