0

I am trying to upload a file to a Flask app and use it as a pandas DataFrame, not store it. I have a Flask app with the following endpoint: ```

@app.route('/upload_file/', methods=['POST'])
def upload_file():

        afile = request.files['file']
        ff = file.read(afile)
        print ff

        return str(ff)
```
I am trying to use curl to use POST to upload the file using:

```curl -v -F file='/Users/asharma/../cpr_all_platforms.csv' http://127.0.0.1:5000/upload_file/```

I get the following error:

```
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> POST /upload_file/ HTTP/1.1
> Host: 127.0.0.1:5000
> User-Agent: curl/7.49.0
> Accept: */*
> Content-Length: 207
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------b313bf20e62c9f7c
> 
< HTTP/1.1 100 Continue
* HTTP 1.0, assume close after body
< HTTP/1.0 400 BAD REQUEST
< Content-Type: text/html
< Content-Length: 192
< Server: Werkzeug/0.11.11 Python/2.7.12
< Date: Fri, 17 Feb 2017 19:00:37 GMT
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
* Closing connection 0

```

0

1 Answer 1

1
@app.route('/upload_file/', methods=['POST'])
def upload_file():

        file = request.files['file']

        ff = pd.read_csv(file)

        return str(ff)

The endpoint is hit using curl and the filename:

curl -i -X POST -F file=@/Users/asharma/../cpr_all_platforms.csv http://127.0.0.1:5000/upload_file/
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.