From 3a1d48cfe0b2238555998aff0110cd8b8a7d494c Mon Sep 17 00:00:00 2001 From: rykci Date: Fri, 24 Feb 2023 17:03:27 -0500 Subject: [PATCH] support 0 byte upload and download --- mcs/api/bucket_api.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mcs/api/bucket_api.py b/mcs/api/bucket_api.py index e6843c9..f4c70fd 100644 --- a/mcs/api/bucket_api.py +++ b/mcs/api/bucket_api.py @@ -128,9 +128,6 @@ def list_files(self, bucket_name, prefix='', limit='10', offset="0"): def upload_file(self, bucket_name, object_name, file_path): prefix, file_name = object_to_filename(object_name) bucket_id = self._get_bucket_id(bucket_name) - if os.stat(file_path).st_size == 0: - print("\033[31mError:File size cannot be 0\033[0m") - return None file_size = os.stat(file_path).st_size with open(file_path, 'rb') as file: file_hash = md5(file.read()).hexdigest() @@ -184,8 +181,9 @@ def download_file(self, bucket_name, object_name, local_filename): if file is not None: ipfs_url = file.ipfs_url with open(local_filename, 'wb') as f: - data = urllib.request.urlopen(ipfs_url) - f.write(data.read()) + if file.size > 0: + data = urllib.request.urlopen(ipfs_url) + f.write(data.read()) print("\033[32mFile download successfully\033[0m") return True print('\033[31mError: File does not exist\033[0m')