From 2761ea47a061dc05f2cf310a7e9e14bb38bdeef5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2025 17:09:42 +0000 Subject: [PATCH] chore(internal): codegen related update --- README.md | 19 +++++++++++++++++++ src/cloudflare/_files.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80cf9e2b565..75adab36957 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,25 @@ 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.api_gateway.user_schemas.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + file=Path("/path/to/file"), + kind="openapi_v3", +) +``` + +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 715cc2078d1..8c03622633a 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