Skip to content
Snippets Groups Projects
Commit 6e4c9a9d authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

storing images in tempfolder for matching and storing

parent be76a47e
No related branches found
No related tags found
1 merge request!18Resolve "refactoring matchsalamander and register location endpoint"
...@@ -2,17 +2,35 @@ from flask import request, jsonify ...@@ -2,17 +2,35 @@ from flask import request, jsonify
from flask_restful import Resource from flask_restful import Resource
from flask_jwt_extended import get_jwt_identity, jwt_required from flask_jwt_extended import get_jwt_identity, jwt_required
ALLOWED_EXTENSIONS = ['jpeg', 'png', 'jpg']
# findSalamanderInfo endpoint # findSalamanderInfo endpoint
class FindSalamanderInfo(Resource): class FindSalamanderInfo(Resource):
@staticmethod @staticmethod
@jwt_required @jwt_required
def post(): def post():
if "image" not in request.files:
return jsonify({"message": "no file given"})
image = request.files['image'] image = request.files['image']
user_id = get_jwt_identity()
if image.filename != '': if image.filename != '':
if image and allowed_image(image.filename):
# run AI on image # run AI on image
output = {"sex": "AI_sex", "species": "AI_species"} # store processed and original image
image.filename = str(user_id) + "." + extension(image.filename)
image.save("temp_images/" + image.filename)
return jsonify({"sex": "AI_sex", "species": "AI_species"})
else:
return jsonify({"message": "file extension not allowed"})
else: else:
output = {"message": "something wrong with image"} return jsonify({"message": "something wrong with image"})
def allowed_image(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
return output def extension(filename):
return filename.rsplit('.', 1)[1].lower()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment