From 288d5d6ce3be91ae393c55fc50242903de01e786 Mon Sep 17 00:00:00 2001 From: luffah Date: Thu, 6 May 2021 14:51:27 +0200 Subject: [PATCH] Add upload_file_contents to File object --- src/nextcloud/api_wrappers/webdav.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/nextcloud/api_wrappers/webdav.py b/src/nextcloud/api_wrappers/webdav.py index 5bbc623..e0c96d0 100644 --- a/src/nextcloud/api_wrappers/webdav.py +++ b/src/nextcloud/api_wrappers/webdav.py @@ -171,7 +171,9 @@ def list(self, subpath='', filter_rules=None, all_properties=False): def upload_file(self, local_filepath, name, timestamp=None): """ Upload file (see WebDav wrapper) + :param local_filepath: path of the local file :param name: name of the new file + :param timestamp (int): timestamp of upload file. If None, get time by local file. :returns: True if success """ resp = self._wrapper.upload_file(local_filepath, @@ -179,6 +181,20 @@ def upload_file(self, local_filepath, name, timestamp=None): timestamp=timestamp) return resp.is_ok + def upload_file_contents(self, file_contents, name=None, timestamp=None): + """ + Upload file content (see WebDav wrapper) + :param file_contents: binary content of the file + :param name: name of the new file (current file if empty) + :param timestamp (int): mtime of upload file + :returns: True if success + """ + resp = self._wrapper.upload_file_contents(file_contents, + self._get_remote_path(name), + timestamp=timestamp) + return resp.is_ok + + def download(self, name=None, target_dir=None): """ Download file (see WebDav wrapper) @@ -332,8 +348,8 @@ def upload_file_contents(self, file_contents, remote_filepath, timestamp=None): Returns: requester response """ - return self.requester.put_with_timestamp((self._get_path(remote_filepath)), data=file_contents, - timestamp=timestamp) + return self.requester.put_with_timestamp( + self._get_path(remote_filepath), data=file_contents, timestamp=timestamp) def create_folder(self, folder_path): """