Error validating image generated by javascript

I’m trying to dynamically create an image by javascript and load it in the form input, despite the image being generated correctly, when validating the form through python an error is returned claiming that the image file is invalid or corrupt.

Follow gist with the code:

I don’t have any idea as to how JavaScript encodes and transfers a File object within the DataTransfer object, but I do know that Django requires file uploads to be supplied in a very specific manner.

See HttpRequest.FILES and Binding uploaded files to a form.

What you might want to do is create a very simple file upload form and capture the data being submitted in the post to see what gets sent on an upload. You could then compare that to what gets submitted by what you have written, and see what might need to be adjusted.