title: Reading file data during form's clean method
body: <p>So, I'm working on implementing the answer to <a href="https://stackoverflow.com/questions/2798670/processing-file-uploads-before-object-is-saved">my previous question</a>.</p>
  
  <p>Here's my model:</p>
  
  <pre><code>class Talk(models.Model):
    title        = models.CharField(max_length=200)
    mp3          = models.FileField(upload_to = u'talks/', max_length=200)
  </code></pre>
  
  <p>Here's my form:</p>
  
  <pre><code>class TalkForm(forms.ModelForm):
    def clean(self):
      super(TalkForm, self).clean()
      cleaned_data = self.cleaned_data
  
      if u'mp3' in self.files:
        from mutagen.mp3 import MP3
        if hasattr(self.files['mp3'], 'temporary_file_path'):
          audio = MP3(self.files['mp3'].temporary_file_path())
        else:
          # What goes here?
          audio = None # setting to None for now
        ...
      return cleaned_data
  
    class Meta:
      model = Talk
  </code></pre>
  
  <p><a href="http://code.google.com/p/mutagen/wiki/Tutorial" rel="nofollow noreferrer">Mutagen</a> needs file-like objects or filenames on disk (I <em>think</em>) - the first case (where the uploaded file is larger than the size of file handled in memory) works fine, but I don't know how to handle <code>InMemoryUploadedFile</code> that I get otherwise. I've tried:</p>
  
  <pre><code># TypeError (coercing to Unicode: need string or buffer, InMemoryUploadedFile found)
  audio = MP3(self.files['mp3'])
  
  # TypeError (coercing to Unicode: need string or buffer, cStringIO.StringO found)
  audio = MP3(self.files['mp3'].file)
  
  # Hangs seemingly indefinitely on my test file (~800KB)
  audio = MP3(self.files['mp3'].file.read())
  </code></pre>
  
  <p>Is there something wrong with mutagen, or am I doing it wrong?</p>
  
  <h2>After rebus' answer</h2>
  
  <p>Modifying the <code>FILE_UPLOAD_HANDLERS</code> setting on the fly in my <code>ModelAdmin</code> class like this:</p>
  
  <pre><code>def add_view(self, request, form_url='', extra_context=None):
    request.upload_handlers = [TemporaryFileUploadHandler()]
    return super(TalkAdmin, self).add_view(request, form_url, extra_context)
  </code></pre>
  
  <p>Gets me the following error 500 when I hit submit:</p>
  
  <blockquote>
    <p>You cannot set the upload handlers after the upload has been processed.</p>
  </blockquote>
  
  <p>even though I'm doing it as early as I possibly can!</p>
  
  <p>Also, I'm not sure I've got a <code>save</code> method on the object I'm getting back (I've looked in <code>dir(self.files['mp3'].file)</code> and <code>dir(self.files['mp3'])</code>).</p>