Skip to content

Commit 1feb3aa

Browse files
committed
Add upload_bytes_file_to_custom_folder()
1 parent 644ccb2 commit 1feb3aa

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎seatable_api/main.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,28 @@ def upload_local_file_to_custom_folder(self, local_path, custom_folder_path = No
12781278
file_name = d.get('name')
12791279
return self.get_custom_file_info(custom_folder_path, file_name)
12801280

1281+
@check_auth
1282+
def upload_bytes_file_to_custom_folder(self, name, content: bytes, custom_folder_path=None, replace=False):
1283+
if not custom_folder_path:
1284+
custom_folder_path = '/'
1285+
1286+
upload_link_dict = self.get_custom_file_upload_link(parse.unquote(custom_folder_path))
1287+
upload_link = upload_link_dict.get('upload_link') + '?ret-json=1'
1288+
parent_path = upload_link_dict.get('parent_path')
1289+
relative_path = upload_link_dict.get('relative_path')
1290+
1291+
response = post(upload_link, data={
1292+
'parent_dir': parent_path,
1293+
'relative_path': relative_path,
1294+
'replace': 1 if replace else 0
1295+
}, files={
1296+
'file': (name, BytesIO(content))
1297+
}, timeout=self.timeout)
1298+
d = response.json()[0]
1299+
1300+
file_name = d.get('name')
1301+
return self.get_custom_file_info(custom_folder_path, file_name)
1302+
12811303
@check_auth
12821304
def get_custom_file_info(self, path, name):
12831305
url = self._app_custom_asset_file_url()

0 commit comments

Comments
 (0)