Give `UploadFile` another try

This commit is contained in:
niten 2023-01-09 10:53:11 -08:00
parent 8254b94a88
commit 1e3012bf7f
1 changed files with 8 additions and 4 deletions

View File

@ -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")