Skip to content

Commit

Permalink
Add upload_file_contents to File object
Browse files Browse the repository at this point in the history
  • Loading branch information
luffah committed May 6, 2021
1 parent e355056 commit 288d5d6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/nextcloud/api_wrappers/webdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,30 @@ 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,
self._get_remote_path(name),
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)
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 288d5d6

Please sign in to comment.