Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download local file [duplicate]

Html File

<button mat-button (click) = "FileDownload">Download</button>

Anugular 4 Component Method

FileDownload()
{
  this.filePath = "D:\SamplePDF.pdf";
  document.loation.href = this.filePath;

}

Here, I want to download the local file when button click happens. I am not able to download the file. Please help.

PS: I am not able to access window.open() also as I am using angular 4 application.

like image 418
Billy Avatar asked Nov 27 '22 17:11

Billy


1 Answers

Can you try this snippet

function downloadFunc(){
    	var anchor=document.createElement('a');
    	anchor.setAttribute('href','D:/SamplePDF.pdf');
    	anchor.setAttribute('download','');
    	document.body.appendChild(anchor);
    	anchor.click();
    	anchor.parentNode.removeChild(anchor);
  }
like image 63
Patharraj Avatar answered Dec 05 '22 02:12

Patharraj