@@ -78,8 +78,9 @@ def upload(
78
78
presigned_url_response = presigned_url_response ,
79
79
)
80
80
else :
81
- return self .transfer_blob (
81
+ return self .upload_blob_local (
82
82
file_path = file_path ,
83
+ object_name = object_name ,
83
84
presigned_url_response = presigned_url_response ,
84
85
)
85
86
@@ -105,7 +106,9 @@ def upload_blob_s3(
105
106
fields = presigned_url_response .fields
106
107
fields ["file" ] = (object_name , f , "application/x-tar" )
107
108
e = MultipartEncoder (fields = fields )
108
- m = MultipartEncoderMonitor (e , lambda monitor : t .update (min (t .total , monitor .bytes_read ) - t .n ))
109
+ m = MultipartEncoderMonitor (
110
+ e , lambda monitor : t .update (min (t .total , monitor .bytes_read ) - t .n )
111
+ )
109
112
headers = {"Content-Type" : m .content_type }
110
113
res = requests .post (
111
114
presigned_url_response .url ,
@@ -116,7 +119,9 @@ def upload_blob_s3(
116
119
)
117
120
return res
118
121
119
- def upload_blob_gcs (self , file_path : str , presigned_url_response : PresignedURLCreateResponse ):
122
+ def upload_blob_gcs (
123
+ self , file_path : str , presigned_url_response : PresignedURLCreateResponse
124
+ ):
120
125
"""Generic method to upload data to Google Cloud Storage and create the
121
126
appropriate resource in the backend.
122
127
"""
@@ -137,7 +142,9 @@ def upload_blob_gcs(self, file_path: str, presigned_url_response: PresignedURLCr
137
142
)
138
143
return res
139
144
140
- def upload_blob_azure (self , file_path : str , presigned_url_response : PresignedURLCreateResponse ):
145
+ def upload_blob_azure (
146
+ self , file_path : str , presigned_url_response : PresignedURLCreateResponse
147
+ ):
141
148
"""Generic method to upload data to Azure Blob Storage and create the
142
149
appropriate resource in the backend.
143
150
"""
@@ -161,19 +168,34 @@ def upload_blob_azure(self, file_path: str, presigned_url_response: PresignedURL
161
168
)
162
169
return res
163
170
164
- def transfer_blob (
171
+ def upload_blob_local (
165
172
self ,
166
173
file_path : str ,
174
+ object_name : str ,
167
175
presigned_url_response : PresignedURLCreateResponse ,
168
176
):
169
177
"""Generic method to transfer data to the openlayer folder and create the
170
178
appropriate resource in the backend when using a local deployment.
171
179
"""
172
- blob_path = presigned_url_response .storage_uri .replace ("local://" , "" )
173
- dir_path = os .path .dirname (blob_path )
174
- try :
175
- os .makedirs (dir_path , exist_ok = True )
176
- except OSError as exc :
177
- raise _exceptions .OpenlayerError (f"Directory { dir_path } cannot be created" ) from exc
178
- shutil .copyfile (file_path , blob_path )
179
- return None
180
+ with tqdm (
181
+ total = os .stat (file_path ).st_size ,
182
+ unit = "B" ,
183
+ unit_scale = True ,
184
+ unit_divisor = 1024 ,
185
+ colour = "BLUE" ,
186
+ ) as t :
187
+ with open (file_path , "rb" ) as f :
188
+ fields = {"file" : (object_name , f , "application/x-tar" )}
189
+ e = MultipartEncoder (fields = fields )
190
+ m = MultipartEncoderMonitor (
191
+ e , lambda monitor : t .update (min (t .total , monitor .bytes_read ) - t .n )
192
+ )
193
+ headers = {"Content-Type" : m .content_type }
194
+ res = requests .post (
195
+ presigned_url_response .url ,
196
+ data = m ,
197
+ headers = headers ,
198
+ verify = VERIFY_REQUESTS ,
199
+ timeout = REQUESTS_TIMEOUT ,
200
+ )
201
+ return res
0 commit comments