title: Python - What type is flask.request.files.stream supposed to be?
body: <p>In Flask (Flask-0.10.1 installed via pip) I've tried to handle uploaded files like this</p>
  
  <pre><code>f = flask.request.files[input_name]
  stream = f.stream
  # then use the stream
  </code></pre>
  
  <p>But it's confusing that in some cases <code>stream</code> is a <code>BytesIO</code> instance, but also a chance to be a <code>file</code> object.</p>
  
  <p>I've tested in this way</p>
  
  <pre><code>from flask import Flask, request
  import cStringIO
  
  app = Flask('test')
  
  @app.route("/", methods=['POST'])
  def index():
      if request.method == 'POST':
          f = request.files['file']
          print type(f.stream)
  
  def send_file(client, name):
      with open(name, 'rb') as f:
          client.post('/', data={'file': (cStringIO.StringIO(f.read()), name)})
  
  if __name__ == "__main__":
      with app.test_client() as client:
          send_file(client, 'homercat.png')
          send_file(client, 'megacat-2.png')
  </code></pre>
  
  <p>It prints</p>
  
  <pre><code>&lt;type '_io.BytesIO'&gt;
  &lt;type 'file'&gt;
  </code></pre>
  
  <p>The PNG files are from github:</p>
  
  <p><a href="http://octodex.github.com/images/homercat.png" rel="nofollow">http://octodex.github.com/images/homercat.png</a>
  <a href="http://octodex.github.com/images/megacat-2.png" rel="nofollow">http://octodex.github.com/images/megacat-2.png</a></p>
  
  <p>I wonder why Flask behaves in such way. And if I want the uploaded data to go to the database, is it ok to call <code>f.stream.read()</code> in both cases?</p>