如何从curl请求将图像发送到Flask服务器

时间:2017-01-14 22:58:53

标签: python curl flask request python-imaging-library

我想通过curl将图像发送到烧瓶服务器,我正在尝试这个卷曲命令
curl -X POST -F file=image.jpg "http://127.0.0.1:5000/" 但它在服务器端无法正常工作我通过此代码处理图像
image = Image.open(request.files['file'])我正在尝试使用PIL读取图像
无论如何要做到这一点?
提前致谢

1 个答案:

答案 0 :(得分:4)

这对我有用:

curl -F "file=@image.jpg" http://localhost:5000/

' @'很重要,否则你最终会得到一个http错误400(服务器无法理解请求)。我也放弃了" -X POST"因为没必要。

我的烧瓶视图:

from PIL import Image

@app.route("/", methods=["POST"])
def home():
    img = Image.open(request.files['file'])
    return 'Success!'