Created
October 28, 2010 17:08
-
-
Save anonymous/651811 to your computer and use it in GitHub Desktop.
How to save HTML5 canvas image to Google App Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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