1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Typescript blob filename without link

Discussão em 'Angular' iniciado por playerone, Novembro 6, 2024 às 07:32.

  1. playerone

    playerone Guest

    How to set file name for blob in typescript? For IE, I can setup file name easily but for Chrome it looks impossible. Basically I need something similar to this solution but with typescript

    downloadFile(data: any) {
    var blob = new Blob([data], {type: 'text/csv'});
    let fileName = 'my-test.csv';

    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    //save file for IE
    window.navigator.msSaveOrOpenBlob(blob, fileName);
    } else {
    //save for other browsers: Chrome, Firefox

    var objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
    }
    }


    this function is called from html UI/angular 2:

    <button type="button" class="btn btn-success"
    (click)="downloadFile('test')">Download <br /> Download </button>

    Continue reading...

Compartilhe esta Página