I found the answer myself, here is a solution in case someone needs it:
On the client side, you will receive an image from the canvas and set it in the form field (hidden char field):
var dataURL = document.getElementById('canvas_id').toDataURL("image/png"); document.getElementById('id_hidden_image_field').value = dataURL;
And on the django side:
Add a hidden field called "hidden_image_field" to the form, which will be used to transfer data. This field is a simple CharField. you can add a max_length constraint to make sure the image has a reasonable size (note: not the dimensions, but the actual size).
to analyze image data:
import re import base64 dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$') ImageData = request.POST.get('hidden_image_field') ImageData = dataUrlPattern.match(ImageData).group(2)
and now ImageData contains binary data, you can just save the file and it should work.
hope this helps.
source share