Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/webdav4/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,13 @@ def upload_fileobj( # noqa: PLR0913
chunk_size: Optional[int] = None,
size: Optional[int] = None,
headers: Optional[Dict[str, str]] = None,
request_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
"""Upload file from file object to given path."""
if headers is None:
headers = {}
if request_kwargs is None:
request_kwargs = {}

# we try to avoid chunked transfer as much as possible
# so we try to use size as a hint if provided.
Expand All @@ -670,6 +673,6 @@ def upload_fileobj( # noqa: PLR0913
content = read_chunks(wrapped, chunk_size=chunk_size or self.chunk_size)

http_resp = self.request(
HTTPMethod.PUT, to_path, content=content, headers=headers
HTTPMethod.PUT, to_path, content=content, headers=headers, **request_kwargs
)
http_resp.raise_for_status()
9 changes: 8 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unittest.mock import MagicMock, patch

import pytest
from httpx import Request, Response
from httpx import Request, Response, Timeout

from webdav4.client import (
BadGatewayError,
Expand Down Expand Up @@ -691,6 +691,13 @@ def test_upload_fobj_size_hints(client: Client):
client.upload_fileobj(wrapped, "foobar", size=6) # type: ignore
assert m.call_args[1]["headers"] == {"Content-Length": "6"}

client.upload_fileobj(
BytesIO(b"foobar"),
"foobar",
request_kwargs={"timeout": Timeout(3, connect=10)},
)
assert m.call_args[1]["timeout"] == Timeout(connect=10, read=3, write=3, pool=3)


def test_upload_file(tmp_path: Path, storage_dir: TmpDir, client: Client):
"""Test uploading a local file to a remote."""
Expand Down