File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 21
21
urlpatterns = [
22
22
path ('admin/' , admin .site .urls ),
23
23
path ('capture/' , views .capture ),
24
+ path ('capture_async/' , views .capture_async ),
24
25
path ('health_check/' , views .health_check ),
25
26
]
Original file line number Diff line number Diff line change
1
+ import io
1
2
from pathlib import Path
2
3
3
4
from django .conf import settings
4
- from django .http import JsonResponse , HttpResponse
5
+ from django .http import JsonResponse , HttpResponse , FileResponse
5
6
from django .views .decorators .http import require_POST , require_GET
6
7
8
+ from go_capture .sgf .process_image import process_image
7
9
from go_capture .tasks import process_image_task
8
10
9
11
10
12
@require_POST
11
13
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 ):
12
30
image_file = request .FILES ['image' ]
13
31
filename = Path (image_file .name )
14
32
output_path = settings .IMAGES_DIR / filename
Original file line number Diff line number Diff line change @@ -11,3 +11,14 @@ Content-Type: image/jpeg
11
11
12
12
< ./images/whole_board/20220305_144247.jpg
13
13
--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--
You can’t perform that action at this time.
0 commit comments