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

编程入门 行业动态 更新时间:2024-10-12 05:50:17
本文介绍了如何从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 "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" 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服务器

本文发布于:2023-10-10 22:24:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   图像   服务器   curl   Flask

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!