Using Flask to load a txt file through the browser and access its data for processing
<p>I am making a data visualization tool that takes input from the user (choosing a file on the computer); processes it in Python with Pandas, Numpy, etc; and displays the data in the browser on a local server.</p>

<p>I am having trouble accessing the data once the file is selected using an HTML input form. </p>

<p>HTML form:</p>

<pre><code>&lt;form action="getfile" method="POST" enctype="multipart/form-data"&gt;
    Project file path: &lt;input type="file" name="myfile"&gt;&lt;br&gt;
    &lt;input type="submit" value="Submit"&gt;
&lt;/form&gt;
</code></pre>

<p>Flask routing:</p>

<pre><code>@app.route("/")
def index():
    return render_template('index.html')

@app.route('/getfile', methods=['GET','POST'])
def getfile():
    if request.method == 'POST':
        result = request.form['myfile']
    else:
        result = request.args.get['myfile']
    return result
</code></pre>

<p>This returns a "Bad Request The browser (or proxy) sent a request that this server could not understand." error. I have tried a number of different ways of getting the data out of the file and simply printing it to the screen to start, and have received a range of errors including "TypeError: 'FileStorage' object is not callable" and "ImmutableMultiDict' object is not callable". Any pointers on how to approach this task correctly are appreciated.</p>

<p>A <code>input type=file</code> data isn't passed in as the <code>form</code> dictionary of a request object. It is passed in as <code>request.files</code> (files dictionary in the request object).</p>

<p>So simply change:</p>

<pre><code>result = request.form['myfile']
</code></pre>

<p>to</p>

<pre><code>result = request.files['myfile']
</code></pre>

python flask