Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2010 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/651811 to your computer and use it in GitHub Desktop.
Save anonymous/651811 to your computer and use it in GitHub Desktop.
How to save HTML5 canvas image to Google App Engine
import re
import base64
# ...
class SaveHandler(webapp.RequestHandler):
dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
def post(self):
# ...
imgdata = self.request.get('imgdata')
imgb64 = self.dataUrlPattern.match(imgdata).group(2)
if imgb64 is not None and len(imgb64) > 0:
datamodel.image = db.Blob(base64.b64decode(imgb64))
// The client side code sends the canvas's content via
// a jQuery post method to server
params = { imgdata : canvas.toDataURL('image/jpeg') };
$.post('/save', params, function (data) { /* ... */ })
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment