如何从curl请求将图像发送到Flask服务器 [英] How to send image to Flask server from curl request

查看:304
本文介绍了如何从curl请求将图像发送到Flask服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过curl将图像发送到烧瓶服务器,我正在尝试此curl命令

curl -X POST -F file = image.jpg http:// 127.0.0.1:5000/
,但是它在服务器端无法正常工作,我通过此代码处理图像
image = Image。 open(request.files ['file'])我正在尝试使用PIL读取图像

反正有这样做吗?

谢谢

I want to send an image by curl to flask server, i am trying this curl command
curl -X POST -F file=image.jpg "http://127.0.0.1:5000/" but it did not work by the way on the server side i handle the image by this code
image = Image.open(request.files['file']) i am trying to read the image using PIL
Is there anyway to do this?
Thanks in advance

推荐答案

这对我有用:

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

@很重要,否则您将遇到一个HTTP错误400(服务器无法理解请求)。我还删除了 -X POST位,因为这是不必要的。

The '@' is important, otherwise you end up with an http error 400 (server could not understand request). I've also dropped the "-X POST" bit as it's unnecessary.

我的烧瓶视图:

from PIL import Image

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

这篇关于如何从curl请求将图像发送到Flask服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆