webdav4
webdav4 copied to clipboard
Extension support for Nextcloud and Owncloud?
Also, look for CreationDate
and ModifiedDate
with X-OC-
headers. See if they should/could be used instead. Also, we should consider supporting touch
and/or modifying datetimes for Owncloud and Nextcloud.
This would be a great feature! Thank you for your work on this.
@amichuda, what feature are you thinking of?
I've added some customizations locally but don't feel save enough for commiting a pull request. So I just leave it here. What it does: optional named parameters for upload_file+upload_file_objects and introducing one that is named headers and is later merged with the chunk_size one.
so I have the git copied to moduls/webdav4 which results in this strange path:
from modules.webdav4.src.webdav4.client import Client, ResourceAlreadyExists
client = Client(nextcloud_url + "/remote.php/dav/files/" + username + '/', auth=(username, password))
local_timestamp = os.path.getmtime(full_path)
client.upload_file(
full_path,
nextcloud_file_path,
headers = {'X-OC-MTIME': str(int(local_timestamp))},
overwrite = True,
callback=progress_callback
)
updated client.py
def upload_file(
self,
from_path: "PathLike[AnyStr]",
to_path: str,
*,
overwrite: bool = False,
chunk_size: int = None,
callback: Callable[[int], Any] = None,
headers: Dict[str, Any] = {}
) -> None:
"""Upload file from local path to a given remote path."""
with open(from_path, mode="rb") as fobj:
self.upload_fileobj(
fobj,
to_path,
**{
'overwrite': overwrite,
'callback': callback,
'chunk_size': chunk_size,
'headers': headers
}
)
def upload_fileobj(
self,
file_obj: BinaryIO,
to_path: str,
*,
overwrite: bool = False,
callback: Callable[[int], Any] = None,
chunk_size: int = None,
size: int = None,
headers: Dict[str, Any] = {}
) -> None:
"""Upload file from file object to given path."""
# we try to avoid chunked transfer as much as possible
# so we try to use size as a hint if provided.
# else, we will try to find that out from the file object
# if we are not successful in that, we gracefully fallback
# to the chunked encoding.
if size is None:
size = peek_filelike_length(file_obj)
# merge headers plus content-length
headers = headers | {"Content-Length": str(size)} if size is not None else None
if not overwrite and self.exists(to_path):
raise ResourceAlreadyExists(to_path)
wrapped = wrap_file_like(file_obj, callback)
content = read_chunks(
wrapped, chunk_size=chunk_size or self.chunk_size
)
http_resp = self.request(
HTTPMethod.PUT, to_path, content=content, headers=headers
)
http_resp.raise_for_status()
if somebody could tell me how arguments should work for the lib I'd gladly adjust my code and try a pull request...
Hi, I am open to support headers=
in client.upload_fileobj()
and client.upload_file()
.
Including the optional named things I did?
Closed by #176