Raiper34
Raiper34

Reputation: 537

Electron downloading files like in ordinary browser

I am developing Ionic progressive app that is wraped into Electron. I am using <a href="http://myexternalserver.com/example.pdf" download> to download file. In browser it works, file is downloaded to download folder, but in electron Saving dialog is opened, but after click Save, file is not saved... I do not know why. I really need this functionality in my Ionic Electron app, simply download file to Download folder or ask user to choose folder for file to download... THere is no much ressources on internet and I am lost actualy. Why download attribute do not work?

Thanks for every help,

Filip.

Upvotes: 1

Views: 1638

Answers (1)

Raiper34
Raiper34

Reputation: 537

I solved it using FileSaver. For anyone who is interested code here:

this.http.get('http://myexternalserver.com/example.pdf', {
  responseType: 'arraybuffer',
}).subscribe((data) => {
    const file = new Blob([data], {type: 'application/pdf'});
    FileSaver.saveAs(file, 'example.pdf');
};

Upvotes: 1

Related Questions