I use the following code to download some binary data (a PDF document) and open result in a new tab :
$.ajax({
url: this.downloadurl,
xhrFields: {
responseType: "blob"
}
})
.done(blob => {
var url = URL.createObjectURL(blob);
//open blob in new tab
window.open(url);
//additionally, download the document
var a = $("<a>", {
href: url,
download: this.filename,
}).appendTo(document.body);
a[0].click();
});
It also download the document automatically because I found out that it’s not possible to download it using the download icon in the preview.
Here is the PDF document preview in Chrome. If I click on download icon :
It will give this :
Is there a way to prevent this ?
It looks like the URL can only be used once.