How to download multiple file in angular 2 -
this code download file in angular 2. want download pdf, txt, docx, excel file code. used file saver can download diffrent files on click of button.
public downloadcsvfile() { this.downloadpdf().subscribe( (res) => { //console.log(res); saveas(res,'frontend.xlsx') } ); } public downloadpdf(): { let urls='assets/files/frontend.xlsx' let headers = new headers(); //headers.append('authorization', 'jwt ' + localstorage.getitem('id_token')); return this.http.get(urls, { headers: headers,responsetype: responsecontenttype.blob }).map( (res) => { return new blob([res.blob()], { type: 'application/vnd.ms-excel' }) }) }
this html code how download diffrent file. file name displayed in table want corrosponding file downloaded.
<tr *ngfor ="let mydrive of providermydrive"> <td>{{ mydrive.name }}</td> <td>{{ mydrive.filetype }}</td> <td>{{ mydrive.size }}</td> <td>{{ mydrive.uploaddate }}</td> <td><input type="button" (click)="downloadcsvfile()" value="download"></td> <td></td> </tr>
just create link , click it:
this.storageservice.downloadfile(path).subscribe( res => { let link = document.createelement('a'); link.href = window.url.createobjecturl(res.blob()); link.download = path; link.click(); }, error => this.globalservice.errorsubject.next(error) );
wiki
Comments
Post a Comment