Reputation: 3843
I want my flask server to accept a json file and print it.
I am sending the json with:
curl -X POST -F file=@/home/user1/Desktop/test.json 0.0.0.0:5000/testjson
This is the server's code:
@app.route('/testjson', methods=['POST'])
def trigger_json_test():
POST_content = request.get_json()
print(POST_content)
return make_response(json.dumps({'fileid': "ok"}), 200)
While the server responds with the correct response, all i see to the terminal regarding the print()
is None
Upvotes: 1
Views: 354
Reputation: 2022
request.get_json()
allows you to get the json passed in the body of the http request (obviously if you have specified application/json
as the content type of the request in the header).
If you send the json as a file, then you can get it via the files property of request object:
sent_files = request.files #request.files contains all file sent by the client
Upvotes: 1