Skip to content

Commit ad1daf1

Browse files
committed
Implement /capture_async/ endpoint with fastapi
1 parent bd13a8a commit ad1daf1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import io
2+
from pathlib import Path
23
from typing import Annotated
34

4-
from fastapi import FastAPI, File, UploadFile
5+
from fastapi import FastAPI, File, UploadFile, Form
56

7+
import settings
68
from sgf.process_image import process_image
9+
from tasks import process_image_task
710

811
app = FastAPI()
912

@@ -22,3 +25,15 @@ def capture(image: Annotated[UploadFile, File()]):
2225
'sgf': output_file.read(),
2326
'image_filename': image.filename,
2427
}
28+
29+
30+
@app.post('/capture_async/')
31+
def capture_async(
32+
image: Annotated[UploadFile, File()],
33+
fcm_registration_token: Annotated[str, Form()]
34+
):
35+
filename = Path(image.filename)
36+
output_path = settings.IMAGES_DIR / filename
37+
with output_path.open("wb") as output_file:
38+
output_file.write(image.file.read())
39+
process_image_task.delay(str(output_path.absolute()), fcm_registration_token)

0 commit comments

Comments
 (0)