title: Pyramid - uploading images and storing on disk
body: <p>I'm trying to implement a system of uploading a file (image) to the server running pyramid. Right now, this code gives me an <code>AttributeError: 'unicode' object has no attribute 'file'</code> exception:</p>
  
  <p>Server-side:</p>
  
  <pre><code>session = Session()
  username = authenticated_userid(request)
  if username == None:
      return HTTPNotFound()
  else:
      user = session.query(User).filter(User.username == username).first()
  if 'photo.submitted' in request.params:
      input_file = request.POST['file_input'].file
      tmp = '../static/images/%s' % (session.query(ProfilePic).order_by(-ProfilePic.photo_id).first().photo_id + 1)
      open(tmp, 'w').write(input_file.read())
      tmp.close()
      return Response('OK')
  return {}
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;form action="/settings" method="post"&gt;
          &lt;input type="file" name="file_input" value="Choose image" /&gt;
  
  
      &lt;p&gt;&lt;input type="submit" name="photo.submitted" value="Save" /&gt;&lt;/p&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Something that seems simple, but won't work. I was trying to follow <a href="http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/static_assets/files.html" rel="nofollow">this</a> tutorial, but it seems it only works with video/audio files. How could I make this work?</p>