How can I render the blobstore AppEngine image on HTML5 canvas?
I would like to display a PNG AppEngine blobstore image on an HTML5 canvas. This is what I have tried so far, based on the HTML5 tutorials and using the webapp template to pass the PNG image and its dimensions to the client:
<html>
<head>
<script type="text/javascript">
function draw(png) {
var ctx = document.getElementById('image').getContext('2d');
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0)
};
img.src = png;
}
</script>
</head>
<body onload="draw({{png}});">
<canvas id="image" width={{width}} height={{height}}></canvas>
</body>
</html>
Statement
img.src = png
I think this is wrong because the SRC attribute of the JavaScript Image must be the file name on the server side. But there are no server side files in App Engine, so is there a way to do this?
thank
Mort
source to share
Images come out of blobstore using a servlet (or equivalent in python) as a byte array. You need to write code to write this back to the client the way they understand it. In java it usually looks like this:
BlobKey blobKey = new BlobKey(req.getParameter("blobkey"));
blobstoreService.serve(blobKey, resp);
Are we using urlRewriteFilter (tuckey.org) to rewrite urls like /image/.png to a servlet / service call? blobKey = so browsers know they are fetching an image.
source to share