@@ -82,7 +82,7 @@ def move(self, from_path: str, to_path: str):
82
82
try :
83
83
response = requests .post (
84
84
f"{ self .url } /object/move" ,
85
- data = {
85
+ json = {
86
86
"bucketId" : self .bucket_id ,
87
87
"sourceKey" : from_path ,
88
88
"destinationKey" : to_path ,
@@ -133,6 +133,7 @@ def list(self, path: str = None, options: dict = {}):
133
133
body = dict (self .DEFAULT_SEARCH_OPTIONS , ** options )
134
134
headers = dict (self .headers , ** {"Content-Type" : "application/json" })
135
135
body ["prefix" ] = path if path else ""
136
+
136
137
getdata = requests .post (
137
138
f"{ self .url } /object/list/{ self .bucket_id } " , json = body , headers = headers
138
139
)
@@ -144,5 +145,23 @@ def list(self, path: str = None, options: dict = {}):
144
145
else :
145
146
return getdata .json ()
146
147
148
+ def download (self , path : str ):
149
+ """
150
+ Downloads a file.
151
+ Parameters
152
+ ----------
153
+ path The file path to be downloaded, including the path and file name. For example `folder/image.png`.
154
+ """
155
+ try :
156
+ _path = self ._get_final_path (path )
157
+ response = requests .get (f"{ self .url } /object/{ _path } " , headers = self .headers )
158
+
159
+ except HTTPError as http_err :
160
+ print (f"HTTP error occurred: { http_err } " ) # Python 3.6
161
+ except Exception as err :
162
+ raise err # Python 3.6
163
+ else :
164
+ return response .content
165
+
147
166
def _get_final_path (self , path : str ):
148
167
return f"{ self .bucket_id } /{ path } "
0 commit comments