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
Generating POST Requestpost() method is used to generate a POST request. This method has can contain parameters of URL, params, headers and basic authentication. URL is the location for sending the request. Params are the list of parameters for the request.
Flask has different decorators to handle http requests. Http protocol is the basis for data communication in the World Wide Web. Used to send HTML form data to the server. The data received by the POST method is not cached by the server.
This worked for me:
curl -F "[email protected]" 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!'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With