title: Django upload Form error: 'InMemoryUploadedFile' object has no attribute 'COOKIES'
body: <p>Hi I'm new to Django I'm trying to build a simple upload application.</p>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>from django import forms
  
  class Song(forms.Form):
  song = forms.ImageField()
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  class Song(models.Model):
  song = models.ImageField(upload_to='songs')
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def upload(request):
  
  if request.method  == 'POST':
      form = Song(request.POST, request.FILES)
      if form.is_valid():
          handle_uploaded_file(request.FILES['song'])
          return HttpResponseRedirect('/done/')
  
  else:
      form = Song()
      return render_to_response('upload.html', {
      'form': form},
      context_instance=RequestContext(request)
      )
  
  def handle_uploaded_file(f):
      destination = open('/home/fh/Desktop/netz/media/name.txt', 'wb+')
      for chunk in f.chunks():
          destination.write(chunk)
      destination.close()
  </code></pre>
  
  <p><strong>template</strong></p>
  
  <pre><code>&lt;form action="/upload/" enctype="multipart/form-data" method="post"&gt;{% csrf_token %}
  {{ form.as_p }}
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>When I test it I get this error. And I don' even know what that means. Can anyone figure out what I'm doing wrong?</p>
  
  <pre><code>AttributeError at /upload/
  
  'InMemoryUploadedFile' object has no attribute 'COOKIES'
  
  Request Method:     POST
  Request URL:    http://localhost:8080/upload/
  Django Version:     1.3.1
  Exception Type:     AttributeError
  Exception Value:    
  
  'InMemoryUploadedFile' object has no attribute 'COOKIES'
  
  Exception Location:     /usr/local/lib/python2.6/dist-packages/django/middleware  /csrf.py in process_view, line 116
  Python Executable:  /usr/bin/python
  Python Version:     2.6.6
  Python Path:    
  
  ['/usr/lib/python2.6',
   '/usr/lib/python2.6/plat-linux2',
   '/usr/lib/python2.6/lib-tk',
   '/usr/lib/python2.6/lib-old',
   '/usr/lib/python2.6/lib-dynload',
   '/usr/local/lib/python2.6/dist-packages',
   '/usr/lib/python2.6/dist-packages',
   '/usr/lib/python2.6/dist-packages/PIL',
   '/usr/lib/python2.6/dist-packages/gst-0.10',
   '/usr/lib/pymodules/python2.6',
   '/usr/lib/pymodules/python2.6/gtk-2.0',
   '/home/fh/Desktop/netz/Klangmagnet',
   '/home/fh/Desktop/netz/Klangmagnet/Klangmagnet']
  
  Server time:    Wed, 15 Feb 2012 19:51:30 -0600
  </code></pre>