A rest webservice I'm querying prompts the download modal window when I send a request. This is the response header
{
"access-control-allow-credentials": "true",
"access-control-allow-headers": "x-requested-with, content-type, authorization",
"access-control-allow-methods": "GET, POST, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-disposition": "attachment; filename =AR2.png",
"content-type": "application/octet-stream",
"date": "Tue, 28 Apr 2020 17:17:18 GMT",
"server": "Apache-Coyote/1.1",
"transfer-encoding": "chunked"
}
so if I try to fetch
and print the response body in console I get an unreadable text starting with \89PNG
, of course.
Is there a way to render the PNG in a html page?
I tried Blob and FileReader, but I'm not sure how to use them for this use case.
An attempt I've done
var response = // XHR response
var blob = new Blob([response]);
var imageUrl = urlCreator.createObjectURL(blob);
document.querySelector("#image").src = imageUrl;
The html page just shows the icon of a broken src where the image should be.
I tried to print the whole event
(xhr.onload
callback). responseType
seems empty.