encoding - Save and load image from client to server with django -


here how send data client (coffeescript & dajaxice):

imagedata = canvas.todataurl("image/png") dajaxice.draw.saveimage( @saveimage_callback, {'image': imagedata } ) 

here how save image on server (taken this answer)

@dajaxice_register def saveimage(request, image):     imagedata = re.search(r'base64,(.*)', image).group(1)    output = open('image.png', 'wb')    output.write(imagedata.decode('base64'))    output.close() 

i load image , send so:

inputfile = open('image.png', 'rb') imagedata = inputfile.read().encode('base64') inputfile.close() return simplejson.dumps( { 'image': imagedata } ) 

but not give me exact same data, , client fails draw returned image. imagedata ends 2own9u2 when write it, , 2own when read (missing '9u2').

ok, difference of data not problem, works. here how draw returned image on client:

saveimage_callback: (result)=>     imagedata = 'data:image/png;base64,'+result.image     image = new image()     image.src = imagedata     canvas.getcontext("2d").drawimage(image, 300, 300, 300, 300) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -