#33965: Improve docs for PIL validation of ImageField
-------------------------------------+-------------------------------------
               Reporter:  Timothy    |          Owner:  nobody
  Schilling                          |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  4.1
  Documentation                      |       Keywords:  documentation
               Severity:  Normal     |  imagefield
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 The current docs indicate:

     You may also provide any file-like object (e.g., StringIO or BytesIO)
 as a file handle. If you’re uploading to an ImageField, the object needs a
 name attribute that passes the validate_image_file_extension validator.
 For example:
     {{{
     from io import BytesIO
     img = BytesIO(b'mybinarydata')
     img.name = 'myimage.jpg'
     }}}

 However, this results in the `invalid_image` error for `ImageField` when
 PIL is installed. Some possible code to pass this validation is:

 {{{
 img = BytesIO()
 Image.new("RGB", (1, 1), "#FF0000").save(img, format='PNG')
 img.name = 'myimage.png'
 img.seek(0)
 }}}

 This creates the binary data that's actually an image which passes the
 underlying `PIL.Image.verify()` call.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33965>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070182ec40de3d-df21b604-c260-440d-a9c2-b0a79b6aa547-000000%40eu-central-1.amazonses.com.

Reply via email to