@@ -181,7 +181,15 @@ def put_request(self, endpoint: str, body=None, files=None, data=None):
181181 data = data ,
182182 )
183183
184- def upload (self , endpoint : str , file_path : str , object_name : str = None , body = None ):
184+ def upload (
185+ self ,
186+ endpoint : str ,
187+ file_path : str ,
188+ object_name : str = None ,
189+ body = None ,
190+ method : str = "POST" ,
191+ storage_uri_key : str = "storageUri" ,
192+ ):
185193 """Generic method to upload data to the default storage medium and create the
186194 appropriate resource in the backend.
187195 """
@@ -198,10 +206,18 @@ def upload(self, endpoint: str, file_path: str, object_name: str = None, body=No
198206 file_path = file_path ,
199207 object_name = object_name ,
200208 body = body ,
209+ method = method ,
210+ storage_uri_key = storage_uri_key ,
201211 )
202212
203213 def upload_blob_s3 (
204- self , endpoint : str , file_path : str , object_name : str = None , body = None
214+ self ,
215+ endpoint : str ,
216+ file_path : str ,
217+ object_name : str = None ,
218+ body = None ,
219+ method : str = "POST" ,
220+ storage_uri_key : str = "storageUri" ,
205221 ):
206222 """Generic method to upload data to S3 storage and create the appropriate resource
207223 in the backend.
@@ -235,13 +251,22 @@ def upload_blob_s3(
235251 )
236252
237253 if res .ok :
238- body ["storageUri" ] = presigned_json ["storageUri" ]
239- return self .post_request (f"{ endpoint } " , body = body )
254+ body [storage_uri_key ] = presigned_json ["storageUri" ]
255+ if method == "POST" :
256+ return self .post_request (f"{ endpoint } " , body = body )
257+ elif method == "PUT" :
258+ return self .put_request (f"{ endpoint } " , body = body )
240259 else :
241260 self ._raise_on_respose (res )
242261
243262 def upload_blob_gcs (
244- self , endpoint : str , file_path : str , object_name : str = None , body = None
263+ self ,
264+ endpoint : str ,
265+ file_path : str ,
266+ object_name : str = None ,
267+ body = None ,
268+ method : str = "POST" ,
269+ storage_uri_key : str = "storageUri" ,
245270 ):
246271 """Generic method to upload data to Google Cloud Storage and create the
247272 appropriate resource in the backend.
@@ -265,13 +290,22 @@ def upload_blob_gcs(
265290 timeout = constants .REQUESTS_TIMEOUT ,
266291 )
267292 if res .ok :
268- body ["storageUri" ] = presigned_json ["storageUri" ]
269- return self .post_request (f"{ endpoint } " , body = body )
293+ body [storage_uri_key ] = presigned_json ["storageUri" ]
294+ if method == "POST" :
295+ return self .post_request (f"{ endpoint } " , body = body )
296+ elif method == "PUT" :
297+ return self .put_request (f"{ endpoint } " , body = body )
270298 else :
271299 self ._raise_on_respose (res )
272300
273301 def upload_blob_azure (
274- self , endpoint : str , file_path : str , object_name : str = None , body = None
302+ self ,
303+ endpoint : str ,
304+ file_path : str ,
305+ object_name : str = None ,
306+ body = None ,
307+ method : str = "POST" ,
308+ storage_uri_key : str = "storageUri" ,
275309 ):
276310 """Generic method to upload data to Azure Blob Storage and create the
277311 appropriate resource in the backend.
@@ -298,12 +332,23 @@ def upload_blob_azure(
298332 timeout = constants .REQUESTS_TIMEOUT ,
299333 )
300334 if res .ok :
301- body ["storageUri" ] = presigned_json ["storageUri" ]
302- return self .post_request (f"{ endpoint } " , body = body )
335+ body [storage_uri_key ] = presigned_json ["storageUri" ]
336+ if method == "POST" :
337+ return self .post_request (f"{ endpoint } " , body = body )
338+ elif method == "PUT" :
339+ return self .put_request (f"{ endpoint } " , body = body )
303340 else :
304341 self ._raise_on_respose (res )
305342
306- def transfer_blob (self , endpoint : str , file_path : str , object_name : str , body = None ):
343+ def transfer_blob (
344+ self ,
345+ endpoint : str ,
346+ file_path : str ,
347+ object_name : str ,
348+ body = None ,
349+ method : str = "POST" ,
350+ storage_uri_key : str = "storageUri" ,
351+ ):
307352 """Generic method to transfer data to the openlayer folder and create the appropriate
308353 resource in the backend when using a local deployment.
309354 """
@@ -317,5 +362,8 @@ def transfer_blob(self, endpoint: str, file_path: str, object_name: str, body=No
317362 except OSError as exc :
318363 raise OpenlayerException (f"Directory { dir_path } cannot be created" ) from exc
319364 shutil .copyfile (file_path , blob_path )
320- body ["storageUri" ] = presigned_json ["storageUri" ]
321- return self .post_request (f"{ endpoint } " , body = body )
365+ body [storage_uri_key ] = presigned_json ["storageUri" ]
366+ if method == "POST" :
367+ return self .post_request (f"{ endpoint } " , body = body )
368+ elif method == "PUT" :
369+ return self .put_request (f"{ endpoint } " , body = body )
0 commit comments