Skip to content

Commit 9c421e4

Browse files
committed
Separate route for async image processing
1 parent ad1ad1c commit 9c421e4

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

go_capture/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
urlpatterns = [
2222
path('admin/', admin.site.urls),
2323
path('capture/', views.capture),
24+
path('capture_async/', views.capture_async),
2425
path('health_check/', views.health_check),
2526
]

go_capture/views.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
import io
12
from pathlib import Path
23

34
from django.conf import settings
4-
from django.http import JsonResponse, HttpResponse
5+
from django.http import JsonResponse, HttpResponse, FileResponse
56
from django.views.decorators.http import require_POST, require_GET
67

8+
from go_capture.sgf.process_image import process_image
79
from go_capture.tasks import process_image_task
810

911

1012
@require_POST
1113
def capture(request):
14+
image_file = request.FILES['image']
15+
output_file = io.StringIO()
16+
process_image(image_file, output_file)
17+
output_file.seek(0)
18+
filename = Path(image_file.name).stem
19+
return FileResponse(
20+
output_file.read(),
21+
status=201,
22+
filename=f'${filename}.sgf',
23+
as_attachment=True,
24+
content_type='application/x-go-sgf'
25+
)
26+
27+
28+
@require_POST
29+
def capture_async(request):
1230
image_file = request.FILES['image']
1331
filename = Path(image_file.name)
1432
output_path = settings.IMAGES_DIR / filename

requests.http

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ Content-Type: image/jpeg
1111

1212
< ./images/whole_board/20220305_144247.jpg
1313
--WebAppBoundary--
14+
15+
### POST image
16+
POST {{protocol}}{{host}}:{{port}}/capture_async/
17+
Content-Type: multipart/form-data; boundary=WebAppBoundary
18+
19+
--WebAppBoundary
20+
Content-Disposition: form-data; name="image"; filename="board.jpg"
21+
Content-Type: image/jpeg
22+
23+
< ./images/whole_board/20220305_144247.jpg
24+
--WebAppBoundary--

0 commit comments

Comments
 (0)