File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 123
123
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
124
124
125
125
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
126
+
127
+ IMAGES_DIR = BASE_DIR / 'images'
128
+ IMAGES_DIR .mkdir (exist_ok = True )
Original file line number Diff line number Diff line change 1
1
import io
2
2
from pathlib import Path
3
3
4
- from django .http import FileResponse , JsonResponse
4
+ from django .conf import settings
5
+ from django .http import JsonResponse , HttpResponse
5
6
from django .views .decorators .http import require_POST , require_GET
6
7
7
8
from go_capture .sgf .process_image import process_image
10
11
@require_POST
11
12
def capture (request ):
12
13
image_file = request .FILES ['image' ]
13
- output_file = io .StringIO ()
14
- process_image (image_file , output_file )
15
- output_file .seek (0 )
16
- filename = Path (image_file .name ).stem
17
- return FileResponse (
18
- output_file .read (),
19
- status = 201 ,
20
- filename = f'${ filename } .sgf' ,
21
- as_attachment = True ,
22
- content_type = 'application/x-go-sgf'
23
- )
14
+ filename = Path (image_file .name )
15
+ output_path = settings .IMAGES_DIR / filename
16
+ with output_path .open ('wb' ) as output_file :
17
+ output_file .write (image_file .read ())
18
+ return HttpResponse (status = 201 )
24
19
25
20
26
21
@require_GET
You can’t perform that action at this time.
0 commit comments