Error when downloading file from server ionic 4

Discussão em 'Angular' iniciado por c-mac, Maio 3, 2025.

  1. c-mac

    c-mac Guest

    I am trying to download a file from my server but I keep getting errors.

    [​IMG]

    [​IMG]

    HTML

    <ion-button expand="block" (click)="download()">Download Files</ion-button>


    TS

    download() {
    const url = 'http://ccoulter12.lampt.eeecs.qub.ac.uk/api/files/5d248f949c71e.pdf';
    const path = this.file.dataDirectory;
    const transfer = this.transfer.create();
    transfer.download(url, path + 'myfile.pdf').then(entry => {
    const url = entry.toURL();

    if (this.platform.is('ios')) {
    // this.document.viewDocument(url, 'application/pdf', {});
    window.open(url);
    } else {
    this.fileOpener.open(url, 'application/pdf')
    .then(() => console.log('File is opened'))
    .catch(e => console.log('Error opening file', e));
    }
    });
    }

    Continue reading...

Compartilhe esta Página