简体   繁体   中英

How to send image to Flask server from curl request

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM