diff --git a/mcs/api/bucket_api.py b/mcs/api/bucket_api.py index a667219..2af0959 100644 --- a/mcs/api/bucket_api.py +++ b/mcs/api/bucket_api.py @@ -147,7 +147,7 @@ def list_files(self, bucket_name, prefix='', limit='10', offset="0"): return False - def upload_file(self, bucket_name, object_name, file_path): + def upload_file(self, bucket_name, object_name, file_path, replace=False): prefix, file_name = object_to_filename(object_name) bucket_id = self._get_bucket_id(bucket_name) if os.stat(file_path).st_size == 0: @@ -160,6 +160,10 @@ def upload_file(self, bucket_name, object_name, file_path): if result is None: logging.error("\033[31mCan't find this bucket\033[0m") return + # Replace file if already existed + if result[['data']['file_is_exist']] and replace: + self.delete_file(bucket_name, object_name) + result = self._check_file(bucket_id, file_hash, file_name, prefix) if not (result['data']['file_is_exist']): if not (result['data']['ipfs_is_exist']): with open(file_path, 'rb') as file: