|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from typing import Dict, List, Union, Iterable, Optional |
| 5 | +from typing import Dict, List, Union, Mapping, Iterable, Optional, cast |
6 | 6 | from datetime import datetime |
7 | 7 | from typing_extensions import Literal |
8 | 8 |
|
|
16 | 16 | memory_upload_params, |
17 | 17 | memory_add_bulk_params, |
18 | 18 | ) |
19 | | -from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
20 | | -from .._utils import path_template, maybe_transform, async_maybe_transform |
| 19 | +from .._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given |
| 20 | +from .._utils import extract_files, path_template, maybe_transform, deepcopy_minimal, async_maybe_transform |
21 | 21 | from .._compat import cached_property |
22 | 22 | from .._resource import SyncAPIResource, AsyncAPIResource |
23 | 23 | from .._response import ( |
@@ -549,7 +549,7 @@ def status( |
549 | 549 | def upload( |
550 | 550 | self, |
551 | 551 | *, |
552 | | - file: str, |
| 552 | + file: FileTypes, |
553 | 553 | collection: Optional[str] | Omit = omit, |
554 | 554 | metadata: Optional[str] | Omit = omit, |
555 | 555 | # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
@@ -583,20 +583,22 @@ def upload( |
583 | 583 |
|
584 | 584 | timeout: Override the client-level default timeout for this request, in seconds |
585 | 585 | """ |
| 586 | + body = deepcopy_minimal( |
| 587 | + { |
| 588 | + "file": file, |
| 589 | + "collection": collection, |
| 590 | + "metadata": metadata, |
| 591 | + } |
| 592 | + ) |
| 593 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
586 | 594 | # It should be noted that the actual Content-Type header that will be |
587 | 595 | # sent to the server will contain a `boundary` parameter, e.g. |
588 | 596 | # multipart/form-data; boundary=---abc-- |
589 | 597 | extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
590 | 598 | return self._post( |
591 | 599 | "/memories/upload", |
592 | | - body=maybe_transform( |
593 | | - { |
594 | | - "file": file, |
595 | | - "collection": collection, |
596 | | - "metadata": metadata, |
597 | | - }, |
598 | | - memory_upload_params.MemoryUploadParams, |
599 | | - ), |
| 600 | + body=maybe_transform(body, memory_upload_params.MemoryUploadParams), |
| 601 | + files=files, |
600 | 602 | options=make_request_options( |
601 | 603 | extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
602 | 604 | ), |
@@ -1114,7 +1116,7 @@ async def status( |
1114 | 1116 | async def upload( |
1115 | 1117 | self, |
1116 | 1118 | *, |
1117 | | - file: str, |
| 1119 | + file: FileTypes, |
1118 | 1120 | collection: Optional[str] | Omit = omit, |
1119 | 1121 | metadata: Optional[str] | Omit = omit, |
1120 | 1122 | # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
@@ -1148,20 +1150,22 @@ async def upload( |
1148 | 1150 |
|
1149 | 1151 | timeout: Override the client-level default timeout for this request, in seconds |
1150 | 1152 | """ |
| 1153 | + body = deepcopy_minimal( |
| 1154 | + { |
| 1155 | + "file": file, |
| 1156 | + "collection": collection, |
| 1157 | + "metadata": metadata, |
| 1158 | + } |
| 1159 | + ) |
| 1160 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
1151 | 1161 | # It should be noted that the actual Content-Type header that will be |
1152 | 1162 | # sent to the server will contain a `boundary` parameter, e.g. |
1153 | 1163 | # multipart/form-data; boundary=---abc-- |
1154 | 1164 | extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
1155 | 1165 | return await self._post( |
1156 | 1166 | "/memories/upload", |
1157 | | - body=await async_maybe_transform( |
1158 | | - { |
1159 | | - "file": file, |
1160 | | - "collection": collection, |
1161 | | - "metadata": metadata, |
1162 | | - }, |
1163 | | - memory_upload_params.MemoryUploadParams, |
1164 | | - ), |
| 1167 | + body=await async_maybe_transform(body, memory_upload_params.MemoryUploadParams), |
| 1168 | + files=files, |
1165 | 1169 | options=make_request_options( |
1166 | 1170 | extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
1167 | 1171 | ), |
|
0 commit comments