hyttekamera/server/api.py

22 lines
646 B
Python
Raw Normal View History

2022-01-18 15:34:10 +00:00
from flask import Flask, request, jsonify
from PIL import Image
import datetime
2022-01-21 11:12:22 +00:00
import config
2022-01-18 15:34:10 +00:00
app = Flask(__name__)
@app.route("/post_img", methods=["POST"])
def process_image():
2022-01-21 11:12:22 +00:00
if request.headers.get('Authorization') == 'Basic ' + config.api['key']:
2022-01-18 15:34:10 +00:00
file = request.files['image']
# Read the image via file.stream
img = Image.open(file.stream)
2022-01-21 11:12:22 +00:00
img = img.rotate(90, expand=True)
2022-01-18 15:34:10 +00:00
time = str(datetime.datetime.now().isoformat(timespec='minutes'))
2022-01-21 11:12:22 +00:00
img.save("./images/"+time+".jpg")
2022-01-18 15:34:10 +00:00
return jsonify({'msg': 'success'})
2022-01-21 11:12:22 +00:00
else:
return jsonify({'msg': 'auth_fail'})
2022-01-18 15:34:10 +00:00
if __name__ == "__main__":
app.run(debug=True)