How to send image to Flask server from curl request

喜夏-厌秋 提交于 2020-07-05 08:29:10

问题


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


回答1:


This worked for me:

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

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.

My flask view:

from PIL import Image

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


来源:https://stackoverflow.com/questions/41655946/how-to-send-image-to-flask-server-from-curl-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!