28
28
from requests_toolbelt import MultipartEncoder , MultipartEncoderMonitor
29
29
from tqdm import tqdm
30
30
from tqdm .utils import CallbackIOWrapper
31
+ import urllib .parse
31
32
32
33
from . import constants
33
34
from .exceptions import ExceptionMap , OpenlayerException
@@ -189,6 +190,8 @@ def upload(
189
190
body = None ,
190
191
method : str = "POST" ,
191
192
storage_uri_key : str = "storageUri" ,
193
+ presigned_url_endpoint : str = "storage/presigned-url" ,
194
+ presigned_url_query_params : str = "" ,
192
195
):
193
196
"""Generic method to upload data to the default storage medium and create the
194
197
appropriate resource in the backend.
@@ -201,13 +204,16 @@ def upload(
201
204
upload = self .upload_blob_azure
202
205
else :
203
206
upload = self .transfer_blob
207
+
204
208
return upload (
205
209
endpoint = endpoint ,
206
210
file_path = file_path ,
207
211
object_name = object_name ,
208
212
body = body ,
209
213
method = method ,
210
214
storage_uri_key = storage_uri_key ,
215
+ presigned_url_endpoint = presigned_url_endpoint ,
216
+ presigned_url_query_params = presigned_url_query_params ,
211
217
)
212
218
213
219
def upload_blob_s3 (
@@ -218,12 +224,18 @@ def upload_blob_s3(
218
224
body = None ,
219
225
method : str = "POST" ,
220
226
storage_uri_key : str = "storageUri" ,
227
+ presigned_url_endpoint : str = "storage/presigned-url" ,
228
+ presigned_url_query_params : str = "" ,
221
229
):
222
230
"""Generic method to upload data to S3 storage and create the appropriate
223
231
resource in the backend.
224
232
"""
233
+
225
234
presigned_json = self .post_request (
226
- f"storage/presigned-url?objectName={ object_name } "
235
+ (
236
+ f"{ presigned_url_endpoint } ?objectName={ object_name } "
237
+ f"&{ presigned_url_query_params } "
238
+ )
227
239
)
228
240
229
241
with tqdm (
@@ -236,7 +248,7 @@ def upload_blob_s3(
236
248
with open (file_path , "rb" ) as f :
237
249
# Avoid logging here as it will break the progress bar
238
250
fields = presigned_json ["fields" ]
239
- fields ["file" ] = (presigned_json [ "id" ] , f , "application/x-tar" )
251
+ fields ["file" ] = (object_name , f , "application/x-tar" )
240
252
e = MultipartEncoder (fields = fields )
241
253
m = MultipartEncoderMonitor (
242
254
e , lambda monitor : t .update (min (t .total , monitor .bytes_read ) - t .n )
@@ -267,12 +279,17 @@ def upload_blob_gcs(
267
279
body = None ,
268
280
method : str = "POST" ,
269
281
storage_uri_key : str = "storageUri" ,
282
+ presigned_url_endpoint : str = "storage/presigned-url" ,
283
+ presigned_url_query_params : str = "" ,
270
284
):
271
285
"""Generic method to upload data to Google Cloud Storage and create the
272
286
appropriate resource in the backend.
273
287
"""
274
288
presigned_json = self .post_request (
275
- f"storage/presigned-url?objectName={ object_name } "
289
+ (
290
+ f"{ presigned_url_endpoint } ?objectName={ object_name } "
291
+ f"&{ presigned_url_query_params } "
292
+ )
276
293
)
277
294
with open (file_path , "rb" ) as f :
278
295
with tqdm (
@@ -306,12 +323,17 @@ def upload_blob_azure(
306
323
body = None ,
307
324
method : str = "POST" ,
308
325
storage_uri_key : str = "storageUri" ,
326
+ presigned_url_endpoint : str = "storage/presigned-url" ,
327
+ presigned_url_query_params : str = "" ,
309
328
):
310
329
"""Generic method to upload data to Azure Blob Storage and create the
311
330
appropriate resource in the backend.
312
331
"""
313
332
presigned_json = self .post_request (
314
- f"storage/presigned-url?objectName={ object_name } "
333
+ (
334
+ f"{ presigned_url_endpoint } ?objectName={ object_name } "
335
+ f"&{ presigned_url_query_params } "
336
+ )
315
337
)
316
338
with open (file_path , "rb" ) as f :
317
339
with tqdm (
@@ -348,12 +370,17 @@ def transfer_blob(
348
370
body = None ,
349
371
method : str = "POST" ,
350
372
storage_uri_key : str = "storageUri" ,
373
+ presigned_url_endpoint : str = "storage/presigned-url" ,
374
+ presigned_url_query_params : str = "" ,
351
375
):
352
376
"""Generic method to transfer data to the openlayer folder and create the
353
377
appropriate resource in the backend when using a local deployment.
354
378
"""
355
379
presigned_json = self .post_request (
356
- f"storage/presigned-url?objectName={ object_name } "
380
+ (
381
+ f"{ presigned_url_endpoint } ?objectName={ object_name } "
382
+ f"&{ presigned_url_query_params } "
383
+ )
357
384
)
358
385
blob_path = presigned_json ["storageUri" ].replace ("local://" , "" )
359
386
dir_path = os .path .dirname (blob_path )
0 commit comments