In my backend API, i am streaming a pdf in application/octet-stream format.
In front end, for any browser i just create a blob, and open it after:
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.setRequestHeader("Authorization", "Bearer " + token);
request.responseType = "arraybuffer";
request.send();
request.onload = function () {
var blob = new Blob([this.response], { type: blobType }),newUrl = URL.createObjectURL(blob);
window.open(newUrl, "_blank", "menubar=yes,resizable=yes,scrollbars=yes");
And this works.
Internet explorer though, doesn't support blob, and i have to open it with:
window.navigator.msSaveOrOpenBlob(blob);
This will prompt the usual save or open file in IE. But i would like to open it straight in a new window.
I tried to use:
...
request.responseType = "application/pdf";
...
window.open("data:application/pdf," + this.response, "_blank", "menubar=yes,resizable=yes,scrollbars=yes");
and i tried as well
window.open("data:application/pdf;base64," + this.response, "_blank", "menubar=yes,resizable=yes,scrollbars=yes");
But it doesn't work.
Any of you knows how to open the pdf? what response type do i need to use? and then how to open it with window.open? Thanks