Skip to content

Commit a1898fc

Browse files
authored
Merge pull request #31 from codeguru42/17-dynamic-file-name
17 dynamic file name
2 parents 8d17c87 + b80e5bf commit a1898fc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

go_capture/views.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
from pathlib import Path
23

34
import cv2
45
import numpy as np
@@ -16,10 +17,17 @@ def capture(request):
1617
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
1718
board = perspective.get_grid(image)
1819
black, white = find_stones.find_stones(board)
19-
file = io.StringIO()
20-
make_sgf(file, black, white)
21-
file.seek(0)
22-
return FileResponse(file.read(), status=201, as_attachment=True, content_type='application/x-go-sgf')
20+
output_file = io.StringIO()
21+
make_sgf(output_file, black, white)
22+
output_file.seek(0)
23+
filename = Path(image_file.name).stem
24+
return FileResponse(
25+
output_file.read(),
26+
status=201,
27+
filename=f'${filename}.sgf',
28+
as_attachment=True,
29+
content_type='application/x-go-sgf'
30+
)
2331

2432

2533
@require_GET

0 commit comments

Comments
 (0)