This is a very specific problem, and I am yet to find anyone else asking it.
Basically I have a servlet that accepts some parameters and returns a PNG image. I know the servlet works because if I open the page itself with the given parameters, the file is created and downloaded successfully. I need some way of taking this generated PNG and load it into an HTML5 Canvas.
I do NOT have access to changing the servlet and it has to be a POST request as it was not designed by me. My code is essentially just a jQuery post request at this point but here it is:
$.post("../dgexport?format=png",
{
data: localStorage.getItem("dg::export"),
responseType: "blob",
},
function(res){
loadCanvas(res);
});
function loadCanvas(image) {
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
// load image
context.drawImage(image, 0, 0);
}
When I open up the console and look at the data response of the POST request it looks like in the console:
�PNG↵↵IHDR��lD�V pHYs�� IDATx��~---���088'���� IDAT��?��q%�
(this is not the whole thing but I'm hoping it's enough to give a hint to anyone willing to help)
Any help would be greatly appreciated! I've tried a lot of different methods and I'm really stumped on this one.