diff --git a/src/objectifier.py b/src/objectifier.py index 0437791..be10d01 100644 --- a/src/objectifier.py +++ b/src/objectifier.py @@ -111,14 +111,18 @@ def result_to_dict(res, base_url): # return result_to_dict(result, base_url) @app.post("/images") -def analyze_image(request: Request, image: bytes = File()): +def analyze_image(request: Request, image: UploadFile): print("Initiating file receipt, url: " + str(request.url)) base_url = re.sub(r'\/images\/?$', '/analyzed_images/', str(request.url)) - infile = open(incoming_dir / file.filename) + infile = open(incoming_dir / image.filename) file_hash = hashlib.sha256() file_hash.update(image) - with open(infile, "w") as f: - f.write(image) + with open(infile, "wb") as f: + chunk = image.read(buffer_size) + while chunk: + print ("writing " + buffer_size + " bytes") + f.write(chunk) + chunk = image.read(buffer_size) print("save complete") print("analyzing image") result = detector.detect_objects(infile, file_hash.hexdigest() + ".png")