4,827 questions
You will have to write a script to get Blob form the received content and save the Blob in the disk.
Shown below is a sample code which use XMLHttpRequest:
function download() {
var url = "/Home/FileDownload";
var filename = "testfile";
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onreadystatechange = function (e) {
if (this.readyState == 4 && this.status == 200) {
var blob = this.response;
//IE and Edge can use msSaveBlob method
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, filename + ".pdf");
} else {
var a = document.createElement("a");
// IE11 does not support URL API
var url = window.URL;
a.href = url.createObjectURL(new Blob([blob],
{ type: blob.type }));
document.body.appendChild(a);
a.style = "display: none";
a.download = filename + ".pdf";
a.click();
}
}
};
xhr.send();
}
You will be able to use the jQuery 3 or above version. See the following article:
Using jQuery's ajax method to retrieve images as a blob
https://stackoverflow.com/questions/17657184/using-jquerys-ajax-method-to-retrieve-images-as-a-blob