问题
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