我正在尝试将文件上传到Flask应用并将其用作pandas DataFrame,而不是存储它。 我有一个带有以下端点的Flask应用程序: ```
@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/```
我收到以下错误:
```
* 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 :(得分:0)
@app.route('/upload_file/', methods=['POST'])
def upload_file():
file = request.files['file']
ff = pd.read_csv(file)
return str(ff)
使用curl和文件名命中端点:
curl -i -X POST -F file=@/Users/asharma/../cpr_all_platforms.csv http://127.0.0.1:5000/upload_file/