I have a blob
. This is the image I changed using <canvas>
. I verified that the data is correct by translating it into a url to validate it as an MDN guide . So far, so good. Now I would like to publish it on my Django server (along with some other inputs).
So, I am doing this:
var fd = new FormData(form); canvas.toBlob( function(blob) { fd.set("image0", blob, "image0.jpg"); }, "image/jpeg", 0.7); var xhr = new XMLHttpRequest(); xhr.open('POST', '/ajax-upload/', true); xhr.setRequestHeader("X-CSRFToken", csrftoken); xhr.send(fd);
I am checking the POST message using the network inspector console. My blob is confirmed as being sent with a POST request, and I can see how binary data is sent as the "image0" field.
-----------------------------1773139883502878911993383390 Content-Disposition: form-data; name="image0"; filename="blob" Content-Type: image/png
So, I am processing a POST request with this view, available at url /ajax-upload/
:
def ajax_upload(request): if request.method == 'POST': print(request.POST.urlencode())
It doesnβt give me anything. As soon as I find out where my blob went, how can I turn it into Image
? Something like img = Image.open(request.POST["image0"])
?
Esher source share