@@ -97,3 +97,35 @@ def get_sas_url(self, container_name: str, file_path: str, expiry_hours:int = 1
9797 )
9898 sas_url = f"https://{ self ._blob_service_client .account_name } .blob.core.windows.net/{ container_name } /{ file_path } ?{ sas_token } "
9999 return sas_url
100+
101+ def get_container_info (self , file_url :str ):
102+ """
103+ Retrieves the container name and file path from a file URL.
104+
105+ Args:
106+ file_url (str): The URL of the file.
107+
108+ Returns:
109+ tuple: A tuple containing the container name and file path.
110+ """
111+ container_name = file_url .split ('/' )[3 ]
112+ file_path = '/' .join (file_url .split ('/' )[4 :])
113+ return container_name , file_path
114+
115+
116+ def clone_file (self , file_url :str , destination_container_name :str , destination_file_path :str ):
117+ """
118+ Clones a file from one container to another.
119+
120+ Args:
121+ file_url (str): The URL of the file to clone.
122+ destination_container_name (str): The name of the destination container.
123+ destination_file_path (str): The path of the destination file.
124+ """
125+ source_container_name , source_file_path = self .get_container_info (file_url )
126+ source_container = self ._blob_service_client .get_container_client (source_container_name )
127+ source_blob = source_container .get_blob_client (source_file_path )
128+ destination_container = self ._blob_service_client .get_container_client (destination_container_name )
129+ destination_blob = destination_container .get_blob_client (destination_file_path )
130+ destination_blob .start_copy_from_url (source_blob .url )
131+ return destination_blob
0 commit comments