From 5212aa9837845de48ae23a447683bae57161784d Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 18 Jan 2022 16:34:10 +0100 Subject: [PATCH] Moved files --- camera/upload_img.py | 10 ++++++++++ server/api.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 camera/upload_img.py create mode 100644 server/api.py diff --git a/camera/upload_img.py b/camera/upload_img.py new file mode 100644 index 0000000..1dda294 --- /dev/null +++ b/camera/upload_img.py @@ -0,0 +1,10 @@ +from flask import Flask, request, jsonify +import requests + +url = 'http://127.0.0.1:5000/post_img' +my_img = {'image': open('/home/trygve/Pictures/boiled.png', 'rb')} +r = requests.post(url, files=my_img) + +# convert server response into JSON format. +print(r.json()) + diff --git a/server/api.py b/server/api.py new file mode 100644 index 0000000..edc92ad --- /dev/null +++ b/server/api.py @@ -0,0 +1,18 @@ +from flask import Flask, request, jsonify +from PIL import Image +import datetime +app = Flask(__name__) + +@app.route("/post_img", methods=["POST"]) +def process_image(): + file = request.files['image'] + # Read the image via file.stream + img = Image.open(file.stream) + time = str(datetime.datetime.now().isoformat(timespec='minutes')) + img.save("./images/"+time+".png") + + return jsonify({'msg': 'success'}) + + +if __name__ == "__main__": + app.run(debug=True)