title: Why ImageField in form always triggers "invalid_image"?
body: <p>I've implemented ImageField to upload images using Pillow verification in <code>Django 1.8</code>. For some reason, I can't submit the form. It always raises this ValidationError in the form (but with FileField this would work):</p>
  
  <blockquote>
    <p>Upload a valid image. The file you uploaded was either not an image or a corrupted image.</p>
  </blockquote>
  
  <p>The weird part of all this is that the ImageField.check method seems to obtain correct MIME type! (see below)</p>
  
  <h2>WHAT I TRIED</h2>
  
  <p>I've tried with JPG, GIF, and PNG formats; none worked.</p>
  
  <p>So I tried to print some variables in <code>django.forms.fields.ImageField</code> modifying the <code>try</code> statement that triggers this error, adding print statements for testing:</p>
  
  <pre><code>try:
      # load() could spot a truncated JPEG, but it loads the entire
      # image in memory, which is a DoS vector. See #3848 and #18520.
      image = Image.open(file)
      # verify() must be called immediately after the constructor.
      damnit = image.verify()
      print 'MY_LOG: verif=', damnit
  
      # Annotating so subclasses can reuse it for their own validation
      f.image = image
      # Pillow doesn't detect the MIME type of all formats. In those
      # cases, content_type will be None.
      f.content_type = Image.MIME.get(image.format)
      print 'MY_LOG: image_format=', image.format
      print 'MY_LOG: content_type=', f.content_type
  </code></pre>
  
  <p>Then I submit a form again to trigger the error after running <code>python manage.py runserver</code> and obtain these lines:</p>
  
  <blockquote>
    <p>MY_LOG: verif= None</p>
    
    <p>MY_LOG: image_format= JPEG</p>
    
    <p>MY_LOG: content_type= image/jpeg</p>
  </blockquote>
  
  <p>Image is correctly identified by Pillow and the try statement is executed until it's last line... and still the except statement is triggered? It makes nosense!</p>
  
  <p>Using the same tactic, I tried to obtain sone useful log from <code>django.db.models.fields.files.ImageField</code> and every of it's parents until <code>Field</code> to print errors lists... all of them empty!</p>
  
  <h2>MY QUESTION</h2>
  
  <p>Is there anything else I can try to spot what is triggering the ValidationError?</p>
  
  <h2>SOME CODE</h2>
  
  <p>models.py</p>
  
  <pre><code>class MyImageModel(models.Model):
      # Using FileField instead would mean succesfull upload
      the_image = models.ImageField(upload_to="public_uploads/", blank=True, null=True)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.views.generic.edit import CreateView
  from django.forms.models import modelform_factory
  
  class MyFormView(CreateView):
      model = MyImageModel
      form_class = modelform_factory(MyImageModel,
                   widgets={}, fields = ['the_image',])
  </code></pre>
  
  <h1>EDIT:</h1>
  
  <p>After trying the tactic suggested by @Alasdair, I obtained this report from <code>e.message</code>:</p>
  
  <blockquote>
    <p>cannot identify image file &lt;_io.BytesIO object at 0x7f9d52bbc770></p>
  </blockquote>
  
  <p>However, the file is successfully uploaded even if I'm not allowed to submit the form. It looks like if, somehow, the path to image wasn't processed correctly (or something else that hinders the image loading in these lines).</p>
  
  <p>I think something is probably failing on these lines (from <code>django.forms.fields.ImageField</code>):</p>
  
  <pre><code># We need to get a file object for Pillow. We might have a path or we might
  # have to read the data into memory.
  if hasattr(data, 'temporary_file_path'):
      file = data.temporary_file_path()
  else:
      if hasattr(data, 'read'):
          file = BytesIO(data.read())
  else:
      file = BytesIO(data['content'])
  </code></pre>
  
  <p>If I explore what properties does this class <code>BytesIO</code> have, maybe I can extract some relevant information about the error...</p>
  
  <h1>EDIT2</h1>
  
  <p><code>data</code> attribute arrives empty! Determining why won't be easy...</p>