File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 124
124
125
125
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
126
126
127
- IMAGES_DIR = BASE_DIR / 'images'
127
+ MEDIA_URL = 'media/'
128
+ MEDIA_ROOT = BASE_DIR / 'media'
129
+ MEDIA_ROOT .mkdir (exist_ok = True )
130
+
131
+ IMAGES_DIR = MEDIA_ROOT / 'images'
128
132
IMAGES_DIR .mkdir (exist_ok = True )
129
133
130
- SGF_DIR = BASE_DIR / 'sgf'
134
+ SGF_DIR = MEDIA_ROOT / 'sgf'
131
135
SGF_DIR .mkdir (exist_ok = True )
132
136
133
137
FIREBASE_CREDENTIALS_FILE = BASE_DIR / env .str ('FIREBASE_CREDENTIALS_FILE' )
Original file line number Diff line number Diff line change
1
+ import io
1
2
import os
2
- from pathlib import Path
3
3
4
4
import firebase_admin
5
5
from celery import Celery
@@ -34,17 +34,17 @@ def debug_task(self):
34
34
@app .task
35
35
def process_image_task (image_filename , fcm_token ):
36
36
print (f'token: { fcm_token } ' )
37
- sgf_filename = f'{ Path (image_filename ).stem } .sgf'
38
- sgf_path = settings .SGF_DIR / sgf_filename
39
37
print (f'Processing { image_filename } ' )
40
38
with open (image_filename , 'rb' ) as image_file :
41
- with open ( sgf_path , 'w' ) as sgf_file :
42
- process_image (image_file , sgf_file )
39
+ sgf_buffer = io . StringIO ()
40
+ process_image (image_file , sgf_buffer )
43
41
44
- # See documentation on defining a message payload.
42
+ sgf_buffer .seek (0 )
43
+ sgf_data = sgf_buffer .read ()
44
+ print (sgf_data )
45
45
message = messaging .Message (
46
46
data = {
47
- 'sgf_file ' : str ( sgf_path ) ,
47
+ 'sgf ' : sgf_data ,
48
48
},
49
49
token = fcm_token ,
50
50
)
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ def capture_async(request):
31
31
fcm_token = request .POST ['fcm_registration_token' ]
32
32
print (f'token: { fcm_token } ' )
33
33
filename = Path (image_file .name )
34
+ print (filename )
34
35
output_path = settings .IMAGES_DIR / filename
35
36
with output_path .open ('wb' ) as output_file :
36
37
output_file .write (image_file .read ())
You can’t perform that action at this time.
0 commit comments