I have a script to download different type files from server side. The code works for text,xml but when the downloaded pdf file, the contant of downloaded file is empty.
let response = this.http.get(this.Url , new Headers({responseType: 'blob'}))
.subscribe(doc => {
if (doc) {
let contentType = doc.headers.get("Content-Type");
let name = doc.headers.get("Content-Disposition").split("=")[1];
let blob = new Blob([doc.text()], {type: contentType});
let a = window.document.createElement("a");
a.href = window.URL.createObjectURL(blob);
a.download = name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
},
error => this.msgService.showError(this.msgs, error));
I can see the doc.text() is returning some byte[]. I also tried {responseType: 'arraybuffer'} with no luck. Can anyone advise what did i do wrong? Thanks
Aucun commentaire:
Enregistrer un commentaire