|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import typing_extensions |
6 | | -from typing import Any, Type, cast |
| 6 | +from typing import Any, Type, Mapping, cast |
7 | 7 |
|
8 | 8 | import httpx |
9 | 9 |
|
|
39 | 39 | VariantsResourceWithStreamingResponse, |
40 | 40 | AsyncVariantsResourceWithStreamingResponse, |
41 | 41 | ) |
42 | | -from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
43 | | -from ...._utils import maybe_transform, async_maybe_transform |
| 42 | +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes |
| 43 | +from ...._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform |
44 | 44 | from ...._compat import cached_property |
45 | 45 | from ...._resource import SyncAPIResource, AsyncAPIResource |
46 | 46 | from ...._response import ( |
@@ -100,8 +100,8 @@ def create( |
100 | 100 | self, |
101 | 101 | *, |
102 | 102 | account_id: str, |
103 | | - id: object | NotGiven = NOT_GIVEN, |
104 | | - file: object | NotGiven = NOT_GIVEN, |
| 103 | + id: str | NotGiven = NOT_GIVEN, |
| 104 | + file: FileTypes | NotGiven = NOT_GIVEN, |
105 | 105 | metadata: object | NotGiven = NOT_GIVEN, |
106 | 106 | require_signed_urls: bool | NotGiven = NOT_GIVEN, |
107 | 107 | url: str | NotGiven = NOT_GIVEN, |
@@ -142,22 +142,24 @@ def create( |
142 | 142 | """ |
143 | 143 | if not account_id: |
144 | 144 | raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 145 | + body = deepcopy_minimal( |
| 146 | + { |
| 147 | + "id": id, |
| 148 | + "file": file, |
| 149 | + "metadata": metadata, |
| 150 | + "require_signed_urls": require_signed_urls, |
| 151 | + "url": url, |
| 152 | + } |
| 153 | + ) |
| 154 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
145 | 155 | # It should be noted that the actual Content-Type header that will be |
146 | 156 | # sent to the server will contain a `boundary` parameter, e.g. |
147 | 157 | # multipart/form-data; boundary=---abc-- |
148 | 158 | extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
149 | 159 | return self._post( |
150 | 160 | f"/accounts/{account_id}/images/v1", |
151 | | - body=maybe_transform( |
152 | | - { |
153 | | - "id": id, |
154 | | - "file": file, |
155 | | - "metadata": metadata, |
156 | | - "require_signed_urls": require_signed_urls, |
157 | | - "url": url, |
158 | | - }, |
159 | | - v1_create_params.V1CreateParams, |
160 | | - ), |
| 161 | + body=maybe_transform(body, v1_create_params.V1CreateParams), |
| 162 | + files=files, |
161 | 163 | options=make_request_options( |
162 | 164 | extra_headers=extra_headers, |
163 | 165 | extra_query=extra_query, |
@@ -421,8 +423,8 @@ async def create( |
421 | 423 | self, |
422 | 424 | *, |
423 | 425 | account_id: str, |
424 | | - id: object | NotGiven = NOT_GIVEN, |
425 | | - file: object | NotGiven = NOT_GIVEN, |
| 426 | + id: str | NotGiven = NOT_GIVEN, |
| 427 | + file: FileTypes | NotGiven = NOT_GIVEN, |
426 | 428 | metadata: object | NotGiven = NOT_GIVEN, |
427 | 429 | require_signed_urls: bool | NotGiven = NOT_GIVEN, |
428 | 430 | url: str | NotGiven = NOT_GIVEN, |
@@ -463,22 +465,24 @@ async def create( |
463 | 465 | """ |
464 | 466 | if not account_id: |
465 | 467 | raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 468 | + body = deepcopy_minimal( |
| 469 | + { |
| 470 | + "id": id, |
| 471 | + "file": file, |
| 472 | + "metadata": metadata, |
| 473 | + "require_signed_urls": require_signed_urls, |
| 474 | + "url": url, |
| 475 | + } |
| 476 | + ) |
| 477 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
466 | 478 | # It should be noted that the actual Content-Type header that will be |
467 | 479 | # sent to the server will contain a `boundary` parameter, e.g. |
468 | 480 | # multipart/form-data; boundary=---abc-- |
469 | 481 | extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
470 | 482 | return await self._post( |
471 | 483 | f"/accounts/{account_id}/images/v1", |
472 | | - body=await async_maybe_transform( |
473 | | - { |
474 | | - "id": id, |
475 | | - "file": file, |
476 | | - "metadata": metadata, |
477 | | - "require_signed_urls": require_signed_urls, |
478 | | - "url": url, |
479 | | - }, |
480 | | - v1_create_params.V1CreateParams, |
481 | | - ), |
| 484 | + body=await async_maybe_transform(body, v1_create_params.V1CreateParams), |
| 485 | + files=files, |
482 | 486 | options=make_request_options( |
483 | 487 | extra_headers=extra_headers, |
484 | 488 | extra_query=extra_query, |
|
0 commit comments