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

How to send image to Flask server from curl request

我想通过 curl 将图像发送到 flask 服务器,我正在尝试这个 curl 命令
curl -X POST -F file=image.jpg "http://127.0.0.1:5000/" 但它在服务器端不起作用 我通过此代码处理图像
image = Image.open(request.files['file']) 我正在尝试使用 PIL
读取图像 有办法吗?
提前致谢

这对我有用:

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!'