Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { ClasePrueba } from 'src/app/clase-prueba';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- private downloadLink = document.createElement("a");
- private dataAplication = 'data:application/;base64,';
- private filebase64 = new ClasePrueba();
- private fileName = "";
- descargarDocumentoBase64() {
- if (this.filebase64.getBase64().tipoMime == "application/pdf") {
- this.fileName = "sample.pdf";
- this.showDoc(this.fileName);
- }
- if (this.filebase64.getBase64().tipoMime == "application/txt") {
- this.fileName = "sample.txt";
- this.showDoc(this.fileName);
- }
- if (this.filebase64.getBase64().tipoMime == "application/docx") {
- this.fileName = "sample.docx";
- this.showDoc(this.fileName);
- }
- }
- showDoc(fileName) {
- const linkSource = this.dataAplication + this.filebase64.getBase64().documento;
- this.downloadLink.href = linkSource;
- this.downloadLink.download = fileName;
- this.downloadLink.click();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement