Skip to content

Commit 89e9d32

Browse files
chore(internal): codegen related update (#2457)
1 parent 02c1e4e commit 89e9d32

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ for account in first_page.result:
142142
# Remove `await` for non-async usage.
143143
```
144144

145+
## File uploads
146+
147+
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)`.
148+
149+
```python
150+
from pathlib import Path
151+
from cloudflare import Cloudflare
152+
153+
client = Cloudflare()
154+
155+
client.api_gateway.user_schemas.create(
156+
zone_id="023e105f4ecef8ad9ca31a8372d0c353",
157+
file=Path("/path/to/file"),
158+
kind="openapi_v3",
159+
)
160+
```
161+
162+
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.
163+
145164
## Handling errors
146165

147166
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.

src/cloudflare/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
3434
if not is_file_content(obj):
3535
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
3636
raise RuntimeError(
37-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37+
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"
3838
) from None
3939

4040

0 commit comments

Comments
 (0)