title: Python Flask chunk data upload not working
body: <p>I am trying to upload a large file (say ~1GB) from client (using Python request.post) to the flask server.</p>
  
  <p>When client sends the request to server in chunks of 1024, server do not read the whole file and save to server 0kb.</p>
  
  <p>Can you please help me in debugging what exactly I am mistaking here.</p>
  
  <p><strong>Server - Flask Code:</strong></p>
  
  <pre><code>from flask import Flask, request, jsonify
  from werkzeug.utils import secure_filename
  import os
  
  app = Flask(__name__)
  
  app.config['UPLOAD_FOLDER'] = 'uploads/'
  
  @app.route("/upload/&lt;filename&gt;", methods=["POST", "PUT"])
  def upload_process(filename):
      filename = secure_filename(filename)
      fileFullPath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
  
      with open(fileFullPath, "wb") as f:
          chunk_size = 1024
          chunk = request.stream.read(chunk_size)
          f.write(chunk)
      return jsonify({'filename': filename})
  
  
  if __name__ == '__main__':
      app.run(host="0.0.0.0", port=int("8080"),debug=True)
  </code></pre>
  
  <p><strong>Client - Request Code</strong></p>
  
  <pre><code>import os
  import requests
  
  
  def read_in_chunks(file_object, chunk_size=1024):
      while True:
          data = file_object.read(chunk_size)
          if not data:
              break
          yield data
  
  
  def main(fname, url):
      content_path = os.path.abspath(fname)
      with open(content_path, 'r') as f:
          try:
              r = requests.post(url, data=read_in_chunks(f))
              print "r: {0}".format(r)
          except Exception, e:
              print e
  
  
  if __name__ == '__main__':
      filename = 'bigfile.zip'  # ~1GB
      url = 'http://localhost:8080/upload/{0}'.format(filename)
      main(filename, url)
  </code></pre>