2828from requests_toolbelt import MultipartEncoder , MultipartEncoderMonitor
2929from tqdm import tqdm
3030from tqdm .utils import CallbackIOWrapper
31+ import urllib .parse
3132
3233from . import constants
3334from .exceptions import ExceptionMap , OpenlayerException
@@ -189,6 +190,8 @@ def upload(
189190 body = None ,
190191 method : str = "POST" ,
191192 storage_uri_key : str = "storageUri" ,
193+ presigned_url_endpoint : str = "storage/presigned-url" ,
194+ presigned_url_query_params : str = "" ,
192195 ):
193196 """Generic method to upload data to the default storage medium and create the
194197 appropriate resource in the backend.
@@ -201,13 +204,16 @@ def upload(
201204 upload = self .upload_blob_azure
202205 else :
203206 upload = self .transfer_blob
207+
204208 return upload (
205209 endpoint = endpoint ,
206210 file_path = file_path ,
207211 object_name = object_name ,
208212 body = body ,
209213 method = method ,
210214 storage_uri_key = storage_uri_key ,
215+ presigned_url_endpoint = presigned_url_endpoint ,
216+ presigned_url_query_params = presigned_url_query_params ,
211217 )
212218
213219 def upload_blob_s3 (
@@ -218,12 +224,18 @@ def upload_blob_s3(
218224 body = None ,
219225 method : str = "POST" ,
220226 storage_uri_key : str = "storageUri" ,
227+ presigned_url_endpoint : str = "storage/presigned-url" ,
228+ presigned_url_query_params : str = "" ,
221229 ):
222230 """Generic method to upload data to S3 storage and create the appropriate
223231 resource in the backend.
224232 """
233+
225234 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+ )
227239 )
228240
229241 with tqdm (
@@ -236,7 +248,7 @@ def upload_blob_s3(
236248 with open (file_path , "rb" ) as f :
237249 # Avoid logging here as it will break the progress bar
238250 fields = presigned_json ["fields" ]
239- fields ["file" ] = (presigned_json [ "id" ] , f , "application/x-tar" )
251+ fields ["file" ] = (object_name , f , "application/x-tar" )
240252 e = MultipartEncoder (fields = fields )
241253 m = MultipartEncoderMonitor (
242254 e , lambda monitor : t .update (min (t .total , monitor .bytes_read ) - t .n )
@@ -267,12 +279,17 @@ def upload_blob_gcs(
267279 body = None ,
268280 method : str = "POST" ,
269281 storage_uri_key : str = "storageUri" ,
282+ presigned_url_endpoint : str = "storage/presigned-url" ,
283+ presigned_url_query_params : str = "" ,
270284 ):
271285 """Generic method to upload data to Google Cloud Storage and create the
272286 appropriate resource in the backend.
273287 """
274288 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+ )
276293 )
277294 with open (file_path , "rb" ) as f :
278295 with tqdm (
@@ -306,12 +323,17 @@ def upload_blob_azure(
306323 body = None ,
307324 method : str = "POST" ,
308325 storage_uri_key : str = "storageUri" ,
326+ presigned_url_endpoint : str = "storage/presigned-url" ,
327+ presigned_url_query_params : str = "" ,
309328 ):
310329 """Generic method to upload data to Azure Blob Storage and create the
311330 appropriate resource in the backend.
312331 """
313332 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+ )
315337 )
316338 with open (file_path , "rb" ) as f :
317339 with tqdm (
@@ -348,12 +370,17 @@ def transfer_blob(
348370 body = None ,
349371 method : str = "POST" ,
350372 storage_uri_key : str = "storageUri" ,
373+ presigned_url_endpoint : str = "storage/presigned-url" ,
374+ presigned_url_query_params : str = "" ,
351375 ):
352376 """Generic method to transfer data to the openlayer folder and create the
353377 appropriate resource in the backend when using a local deployment.
354378 """
355379 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+ )
357384 )
358385 blob_path = presigned_json ["storageUri" ].replace ("local://" , "" )
359386 dir_path = os .path .dirname (blob_path )
0 commit comments