diff --git a/README.md b/README.md index 8047c97241d..2ea1ba530ac 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,23 @@ for account in first_page.result: # Remove `await` for non-async usage. ``` +## File Uploads + +Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`. + +```python +from pathlib import Path +from cloudflare import Cloudflare + +client = Cloudflare() + +client.images.v1.create( + account_id="023e105f4ecef8ad9ca31a8372d0c353", +) +``` + +The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically. + ## Handling errors When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `cloudflare.APIConnectionError` is raised. diff --git a/src/cloudflare/_files.py b/src/cloudflare/_files.py index 0d2022ae79e..de98c29b284 100644 --- a/src/cloudflare/_files.py +++ b/src/cloudflare/_files.py @@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None: if not is_file_content(obj): prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`" raise RuntimeError( - f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead." + f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/cloudflare/cloudflare-python/tree/main#file-uploads" ) from None