# Error validating image generated by javascript

**URL:** <https://forum.djangoproject.com/t/error-validating-image-generated-by-javascript/16468>\
**Category:** Forms & APIs\
**Created:** [October 14, 2022, 3:15pm UTC](https://forum.djangoproject.com/t/error-validating-image-generated-by-javascript/16468 "2022-10-14T15:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![castelhano](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/castelhano/32/10378_2.png) [@castelhano](https://forum.djangoproject.com/u/castelhano)\
**Post date:** [October 14, 2022, 3:15pm UTC](https://forum.djangoproject.com/t/error-validating-image-generated-by-javascript/16468/1 "2022-10-14T15:15:36Z")

</div>

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:

> <https://gist.github.com/castelhano/bd72947e13421606453798bbf219cc74>

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 15, 2022, 3:46am UTC](https://forum.djangoproject.com/t/error-validating-image-generated-by-javascript/16468/2 "2022-10-15T03:46:11Z")

</div>

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](https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.HttpRequest.FILES) and [Binding uploaded files to a form](https://docs.djangoproject.com/en/4.1/ref/forms/api/#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.
