title: Not able to parse a .csv file uploaded using Flask
body: <p>I am trying to upload a CSV file, work on it to produce results, and write back (download) a new CSV file containing the result.
  I am very new to Flask and I am not able to get a "proper" <code>csv.reader</code> object to iterate and work upon.
  Here is the code so far,</p>
  
  <pre><code>__author__ = 'shivendra'
  from flask import Flask, make_response, request
  import csv
  
  app = Flask(__name__)
  
  def transform(text_file_contents):
      return text_file_contents.replace("=", ",")
  
  
  @app.route('/')
  def form():
      return """
          &lt;html&gt;
              &lt;body&gt;
                  &lt;h1&gt;Transform a file demo&lt;/h1&gt;
  
                  &lt;form action="/transform" method="post" enctype="multipart/form-data"&gt;
                      &lt;input type="file" name="data_file" /&gt;
                      &lt;input type="submit" /&gt;
                  &lt;/form&gt;
              &lt;/body&gt;
          &lt;/html&gt;
      """
  
  @app.route('/transform', methods=["POST"])
  def transform_view():
      file = request.files['data_file']
      if not file:
          return "No file"
  
      file_contents = file.stream.read().decode("utf-8")
      csv_input = csv.reader(file_contents)
      print(file_contents)
      print(type(file_contents))
      print(csv_input)
      for row in csv_input:
          print(row)
  
      result = transform(file_contents)
  
      response = make_response(result)
      response.headers["Content-Disposition"] = "attachment; filename=result.csv"
      return response
  
  if __name__ == "__main__":
      app.run(host='0.0.0.0', port=5001, debug=True)
  </code></pre>
  
  <p>The terminal output being</p>
  
  <pre><code>127.0.0.1 - - [12/Oct/2015 02:51:53] "GET / HTTP/1.1" 200 -
  127.0.0.1 - - [12/Oct/2015 02:51:59] "POST /transform HTTP/1.1" 200 -
  4,5,6
  &lt;class 'str'&gt;
  &lt;_csv.reader object at 0x105149438&gt;
  ['1']
  ['', '']
  ['2']
  ['', '']
  ['3']
  []
  ['4']
  ['', '']
  ['5']
  ['', '']
  ['6']
  </code></pre>
  
  <p>Whereas the file I read is</p>
  
  <p><a href="https://i.stack.imgur.com/GNtIf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GNtIf.png" alt="enter image description here"></a></p>
  
  <p>What am I doing wrong to not get 2 lists representing 2 rows when I iterate the csv.reader object?</p>