36
36
# ---------------------------------------------------------------------------- #
37
37
# Upload Image #
38
38
# ---------------------------------------------------------------------------- #
39
- def upload_image (job_id , job_result , result_index = 0 ):
39
+ def upload_image (job_id , image_location , result_index = 0 , results_list = None ):
40
40
'''
41
41
Upload image to bucket storage.
42
42
'''
43
43
if boto_client is None :
44
44
# Save the output to a file
45
45
output = BytesIO ()
46
- img = Image .open (job_result )
46
+ img = Image .open (image_location )
47
47
img .save (output , format = img .format )
48
48
49
49
os .makedirs ("uploaded" , exist_ok = True )
@@ -53,7 +53,7 @@ def upload_image(job_id, job_result, result_index=0):
53
53
return f"uploaded/{ result_index } .png"
54
54
55
55
output = BytesIO ()
56
- img = Image .open (job_result )
56
+ img = Image .open (image_location )
57
57
img .save (output , format = img .format )
58
58
59
59
bucket = time .strftime ('%m-%y' )
@@ -75,6 +75,9 @@ def upload_image(job_id, job_result, result_index=0):
75
75
'Key' : f'{ job_id } /{ result_index } .png'
76
76
}, ExpiresIn = 604800 )
77
77
78
+ if results_list is not None :
79
+ results_list [result_index ] = presigned_url
80
+
78
81
return presigned_url
79
82
80
83
@@ -86,18 +89,20 @@ def files(job_id, file_list):
86
89
Uploads a list of files in parallel.
87
90
Once all files are uploaded, the function returns the presigned URLs list.
88
91
'''
89
- upload_progress = []
92
+ upload_progress = [] # List of threads
93
+ file_urls = [None ] * len (file_list ) # Resulting list of URLs for each file
90
94
91
95
for index , file in enumerate (file_list ):
92
96
new_upload = threading .Thread (
93
97
target = upload_image ,
94
- args = (job_id , file , index )
98
+ args = (job_id , file , index , file_urls )
95
99
)
96
100
97
101
new_upload .start ()
98
102
upload_progress .append (new_upload )
99
103
104
+ # Wait for all uploads to finish
100
105
for upload in upload_progress :
101
106
upload .join ()
102
107
103
- return upload_progress
108
+ return file_urls
0 commit comments