title: Django: PIL image upload from form issue
body: <p>Django: Image upload issue</p>
  
  <p>Python: 3.5</p>
  
  <p>Django: 1.11</p>
  
  <p>I am writing a simple news app that will take an image as part of the article. I have chosen to modify the image creating a thumbnail to be stored in the form with the <code>clean_(field name)</code> function provided by Django Forms.</p>
  
  <p>The issue I am encountering is that after going through the submit and the <code>clean_image</code> function the ImageField validation kicks me back with an error stating that the <code>file extension " is not allowed</code>. </p>
  
  <p>I know the issues is coming from the <code>clean_image</code> function after I save the PIL image and then hand it back over to Django ContentFile to process. Any help will be great.</p>
  
  <p>Form:</p>
  
  <pre><code>from django.conf import settings
  from django.core.files.base import ContentFile
  from django.utils.translation import ugettext_lazy as _
  from .models import News
  from ironcsd.validators import MimetypeValidator
  from datetime import date
  from PIL import Image, ImageEnhance
  from io import StringIO, BytesIO
  import hashlib, mimetypes
  import os, io
  import logging, logging.config
  
  logger = logging.getLogger(__name__)
  
  class NewsForm(forms.ModelForm):
  
      class Meta:
          model = News
          widgets = {
              'details': forms.Textarea(attrs={'id': 'smde-editor'}),
          }
          fields = ('title','details','image')
  
  
      def clean_image(self):
          image = self.cleaned_data.get('image')
          md5 = hashlib.md5()
          md5.update(repr(image.name).encode('utf-8'))
          file_name = md5.hexdigest()
  
          if image._size &gt; 30 * 1024 * 1024:
              raise forms.ValidationError(_('File is too big.'), code='invalid')
  
          image = Image.open(image)
  
          if image.size[0] &lt; 1024 or image.size[1] &lt; 1024:
              raise forms.ValidationError(_('Your image needs to be at least 1024x1024.'))
  
          image.thumbnail([1024,1024], Image.ANTIALIAS)
          image_string = io.BytesIO()
          image.save(image_string, image.format)
          image = ContentFile(image_string.getvalue(), file_name)
  
          return image
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>from django.db import models
  from django.urls import reverse, reverse_lazy
  from ironcsd.models import Audit
  
  class News(Audit):
      title = models.CharField(max_length=255)
      details = models.TextField()
      image = models.ImageField(upload_to='news/%Y/%m/')
  
      class Meta:
          verbose_name_plural = "news"
  
      def __str__(self):
          return self.title
  </code></pre>