title: Django with PIL - '_io.BytesIO' object has no attribute 'name'
body: <p>I'm using PIL to resize an uploaded photo before saving.  Note that I'm using formsets to upload the pictures.  I'm using BytesIO to open the file.  At the last step, I get the error - <code>'_io.BytesIO' object has no attribute 'name'</code>.  Why is this? </p>
  
  <pre><code>def fsbo_create_listing(request):
      PhotoFormSet = formset_factory(OwnerListingPhotoForm, extra=15)
      if request.method == 'POST':
          form = OwnerListingForm(request.POST)
          photo_formset = PhotoFormSet(request.POST, request.FILES)
          if form.is_valid() and photo_formset.is_valid():
              form.instance.user = request.user
              form.save()
              for i in photo_formset:
                  if i.instance.pk and i.instance.photo == '':
                      i.instance.delete()
                  elif i.cleaned_data:
                      temp = i.save(commit=False)
                      temp.listing = form.instance
                      temp.save() # Where the error happens
  </code></pre>
  
  <hr>
  
  <pre><code>def clean_photo(self):
      picture = self.cleaned_data.get('photo')
      # I had to import ImageFieldFile.  If picture is already uploaded, picture would still be retrieved as ImageFieldFile.  The following line checks the variable type of `picture` to determine whether the cleaning should proceed.
      if type(picture) != ImageFieldFile:
          image_field = self.cleaned_data.get('photo')
          image_file = BytesIO(image_field.read())
          image = Image.open(image_file)
          image = ImageOps.fit(image, (512,512,), Image.ANTIALIAS)
          image_file = BytesIO()
          image.save(image_file, 'JPEG', quality=90)
          image_field.file = image_file
          #if picture._size &gt; 2*1024*1024:
              #raise ValidationError("Image file too large.  Max size is 2MB.")
      return picture
  </code></pre>
  
  <hr>
  
  <pre><code>class OwnerListingPhoto(models.Model):
  
      listing = models.ForeignKey(OwnerListing, on_delete=models.CASCADE, related_name='owner_listing_photo')
      photo = models.ImageField(upload_to=owner_listing_folder_name)
  </code></pre>