Posting file to Flask with cURL returns 400 error
<p>I want to post a file using cURL to a Flask view. However, I get a 400 error in response.  Why does the command below fail?</p>

<pre><code>@app.route('/deploy/partial', methods=['POST'])
def postfile():
    try:
        file = request.files['file']
        filename = secure_filename(file.filename)
        file.save(os.path.join('/home/test/test.txt', filename))
        return 'OK', 200
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
</code></pre>

<pre class="lang-none prettyprint-override"><code>curl -X POST -H "Content-Type: multipart/form-data" -F "file=@FILEPATH" http://127.0.0.1:25252/deploy/partial

Unexpected error: &lt;class 'werkzeug.exceptions.HTTPException.wrap.&lt;locals&gt;.newcls'&gt;
127.0.0.1 - - [12/Oct/2016 22:57:43] "POST /deploy/partial HTTP/1.1" 400 

HTTP/1.1 100 Continue

HTTP/1.0 400 BAD REQUEST
Content-Type: text/html
Content-Length: 192
Server: Werkzeug/0.11.11 Python/3.4.3
Date: Wed, 12 Oct 2016 19:31:07 GMT

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
&lt;title&gt;400 Bad Request&lt;/title&gt;
&lt;h1&gt;Bad Request&lt;/h1&gt;
&lt;p&gt;The browser (or proxy) sent a request that this server could not    understand.&lt;/p&gt;
</code></pre>

<p>I got the </p>

<p>Unexpected error: .newcls'></p>

<p>after I accidentally renamed request.form['name'] to request.form['ame']
(note the wrong 'ame') while my form field is
name = StringField(...)</p>

<p>I changed request.form['ame'] to request.form['name'] and the error disappeared, i.e. flask works</p>

<p>Not sure if this is your case too.</p>

python curl flask