Here is a code snippet that I have found useful for testing purposes. It may not be the most elegant solution, but it gets the job done by displaying an image.
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var downloadUrl = URL.createObjectURL(xhttp.response);
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = downloadUrl;
a.download = "";
a.click();
}
};
xhttp.open("GET", fileUrl, true);
xhttp.responseType = "blob";
xhttp.setRequestHeader('Authorization', token);
xhttp.send();
This part of the code is optional and was specific to my use case:
xhttp.setRequestHeader('Authorization', token);
If you are interested in learning more, you can check out this helpful resource on Sending and Receiving Binary Data.