Try using File() instead of UploadFile()
This commit is contained in:
parent
8c6b0fa2fe
commit
24327fe351
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Request, UploadFile
|
||||
from fastapi import FastAPI, HTTPException, Request, UploadFile, File
|
||||
from fastapi.responses import FileResponse
|
||||
from detector import Detector
|
||||
import tempfile
|
||||
|
@ -89,20 +89,36 @@ def result_to_dict(res, base_url):
|
|||
"output": base_url + d.outfile,
|
||||
}
|
||||
|
||||
@app.put("/images/")
|
||||
def analyze_image(file: UploadFile, request: Request):
|
||||
# @app.put("/images")
|
||||
# def analyze_image(file: UploadFile(), request: Request):
|
||||
# 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)
|
||||
# file_hash = hashlib.sha256()
|
||||
# with open(infile, mode="wb") as f:
|
||||
# chunk = f.read(buffer_size)
|
||||
# while chunk:
|
||||
# print("writing chunk")
|
||||
# file_hash.update(chunk)
|
||||
# infile.write(chunk)
|
||||
# chunk=f.read(buffer_size)
|
||||
# print("saving complete")
|
||||
# print("analyzing image")
|
||||
# result = detector.detect_objects(infile, file_hash.hexdigest() + ".png")
|
||||
# print("image analyzed")
|
||||
# remove(infile)
|
||||
# return result_to_dict(result, base_url)
|
||||
|
||||
@app.put("/images")
|
||||
def analyze_image(request: Request, incoming_data: bytes = File()):
|
||||
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)
|
||||
file_hash = hashlib.sha256()
|
||||
with open(infile, mode="wb") as f:
|
||||
chunk = f.read(buffer_size)
|
||||
while chunk:
|
||||
print("writing chunk")
|
||||
file_hash.update(chunk)
|
||||
infile.write(chunk)
|
||||
chunk=f.read(buffer_size)
|
||||
print("saving complete")
|
||||
file_hash.update(incoming_data)
|
||||
with open(infile, "w") as f:
|
||||
f.write(incoming_data)
|
||||
print("save complete")
|
||||
print("analyzing image")
|
||||
result = detector.detect_objects(infile, file_hash.hexdigest() + ".png")
|
||||
print("image analyzed")
|
||||
|
|
Loading…
Reference in New Issue