Skip to content

Commit cc31c09

Browse files
feat(api): manual updates
1 parent 3d6ee2a commit cc31c09

File tree

6 files changed

+108
-97
lines changed

6 files changed

+108
-97
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 42
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-667f7f4988b44bc587d6eb9960ff5c8326e9f7e9b072f3f724f9f54166eff8b1.yml
3-
openapi_spec_hash: f2081864a4abee0480e5ff991b4c936a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-eab9713fd85da68b41e881dfd9cd71f654e8620132da2023bab7dd01e5f7852e.yml
3+
openapi_spec_hash: b5037b26fbe7360c6bfaf9947a65bb85
44
config_hash: 70f9408b8d1dfbcf262a20d6eed50e1c

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ client = ImageKit(
4141
)
4242

4343
response = client.files.upload(
44-
file=b"https://www.example.com/public-url.jpg",
44+
file="https://www.example.com/public-url.jpg",
4545
file_name="file-name.jpg",
4646
)
4747
print(response.video_codec)
@@ -73,7 +73,7 @@ client = AsyncImageKit(
7373

7474
async def main() -> None:
7575
response = await client.files.upload(
76-
file=b"https://www.example.com/public-url.jpg",
76+
file="https://www.example.com/public-url.jpg",
7777
file_name="file-name.jpg",
7878
)
7979
print(response.video_codec)
@@ -110,7 +110,7 @@ async def main() -> None:
110110
http_client=DefaultAioHttpClient(),
111111
) as client:
112112
response = await client.files.upload(
113-
file=b"https://www.example.com/public-url.jpg",
113+
file="https://www.example.com/public-url.jpg",
114114
file_name="file-name.jpg",
115115
)
116116
print(response.video_codec)
@@ -138,7 +138,7 @@ from imagekit import ImageKit
138138
client = ImageKit()
139139

140140
response = client.files.upload(
141-
file=b"raw file contents",
141+
file="https://www.example.com/path/to-image.jpg",
142142
file_name="fileName",
143143
transformation={
144144
"post": [
@@ -167,7 +167,7 @@ from imagekit import ImageKit
167167

168168
client = ImageKit()
169169

170-
client.files.upload(
170+
client.beta.v2.files.upload(
171171
file=Path("/path/to/file"),
172172
file_name="fileName",
173173
)
@@ -192,7 +192,7 @@ client = ImageKit()
192192

193193
try:
194194
client.files.upload(
195-
file=b"https://www.example.com/public-url.jpg",
195+
file="https://www.example.com/public-url.jpg",
196196
file_name="file-name.jpg",
197197
)
198198
except imagekit.APIConnectionError as e:
@@ -238,7 +238,7 @@ client = ImageKit(
238238

239239
# Or, configure per-request:
240240
client.with_options(max_retries=5).files.upload(
241-
file=b"https://www.example.com/public-url.jpg",
241+
file="https://www.example.com/public-url.jpg",
242242
file_name="file-name.jpg",
243243
)
244244
```
@@ -264,7 +264,7 @@ client = ImageKit(
264264

265265
# Override per-request:
266266
client.with_options(timeout=5.0).files.upload(
267-
file=b"https://www.example.com/public-url.jpg",
267+
file="https://www.example.com/public-url.jpg",
268268
file_name="file-name.jpg",
269269
)
270270
```
@@ -308,7 +308,7 @@ from imagekit import ImageKit
308308

309309
client = ImageKit()
310310
response = client.files.with_raw_response.upload(
311-
file=b"https://www.example.com/public-url.jpg",
311+
file="https://www.example.com/public-url.jpg",
312312
file_name="file-name.jpg",
313313
)
314314
print(response.headers.get('X-My-Header'))
@@ -329,7 +329,7 @@ To stream the response body, use `.with_streaming_response` instead, which requi
329329

330330
```python
331331
with client.files.with_streaming_response.upload(
332-
file=b"https://www.example.com/public-url.jpg",
332+
file="https://www.example.com/public-url.jpg",
333333
file_name="file-name.jpg",
334334
) as response:
335335
print(response.headers.get("X-My-Header"))

src/imagekit/resources/files/files.py

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Mapping, Iterable, cast
5+
from typing import Dict, List, Iterable
66
from typing_extensions import Literal
77

88
import httpx
@@ -16,8 +16,8 @@
1616
AsyncBulkResourceWithStreamingResponse,
1717
)
1818
from ...types import file_copy_params, file_move_params, file_rename_params, file_update_params, file_upload_params
19-
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven, FileTypes
20-
from ..._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
19+
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
20+
from ..._utils import maybe_transform, async_maybe_transform
2121
from .metadata import (
2222
MetadataResource,
2323
AsyncMetadataResource,
@@ -368,7 +368,7 @@ def rename(
368368
def upload(
369369
self,
370370
*,
371-
file: FileTypes,
371+
file: str,
372372
file_name: str,
373373
token: str | NotGiven = NOT_GIVEN,
374374
checks: str | NotGiven = NOT_GIVEN,
@@ -579,34 +579,6 @@ def upload(
579579
580580
timeout: Override the client-level default timeout for this request, in seconds
581581
"""
582-
body = deepcopy_minimal(
583-
{
584-
"file": file,
585-
"file_name": file_name,
586-
"token": token,
587-
"checks": checks,
588-
"custom_coordinates": custom_coordinates,
589-
"custom_metadata": custom_metadata,
590-
"description": description,
591-
"expire": expire,
592-
"extensions": extensions,
593-
"folder": folder,
594-
"is_private_file": is_private_file,
595-
"is_published": is_published,
596-
"overwrite_ai_tags": overwrite_ai_tags,
597-
"overwrite_custom_metadata": overwrite_custom_metadata,
598-
"overwrite_file": overwrite_file,
599-
"overwrite_tags": overwrite_tags,
600-
"public_key": public_key,
601-
"response_fields": response_fields,
602-
"signature": signature,
603-
"tags": tags,
604-
"transformation": transformation,
605-
"use_unique_file_name": use_unique_file_name,
606-
"webhook_url": webhook_url,
607-
}
608-
)
609-
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
610582
# It should be noted that the actual Content-Type header that will be
611583
# sent to the server will contain a `boundary` parameter, e.g.
612584
# multipart/form-data; boundary=---abc--
@@ -615,8 +587,34 @@ def upload(
615587
"/api/v1/files/upload"
616588
if self._client._base_url_overridden
617589
else "https://upload.imagekit.io/api/v1/files/upload",
618-
body=maybe_transform(body, file_upload_params.FileUploadParams),
619-
files=files,
590+
body=maybe_transform(
591+
{
592+
"file": file,
593+
"file_name": file_name,
594+
"token": token,
595+
"checks": checks,
596+
"custom_coordinates": custom_coordinates,
597+
"custom_metadata": custom_metadata,
598+
"description": description,
599+
"expire": expire,
600+
"extensions": extensions,
601+
"folder": folder,
602+
"is_private_file": is_private_file,
603+
"is_published": is_published,
604+
"overwrite_ai_tags": overwrite_ai_tags,
605+
"overwrite_custom_metadata": overwrite_custom_metadata,
606+
"overwrite_file": overwrite_file,
607+
"overwrite_tags": overwrite_tags,
608+
"public_key": public_key,
609+
"response_fields": response_fields,
610+
"signature": signature,
611+
"tags": tags,
612+
"transformation": transformation,
613+
"use_unique_file_name": use_unique_file_name,
614+
"webhook_url": webhook_url,
615+
},
616+
file_upload_params.FileUploadParams,
617+
),
620618
options=make_request_options(
621619
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
622620
),
@@ -939,7 +937,7 @@ async def rename(
939937
async def upload(
940938
self,
941939
*,
942-
file: FileTypes,
940+
file: str,
943941
file_name: str,
944942
token: str | NotGiven = NOT_GIVEN,
945943
checks: str | NotGiven = NOT_GIVEN,
@@ -1150,34 +1148,6 @@ async def upload(
11501148
11511149
timeout: Override the client-level default timeout for this request, in seconds
11521150
"""
1153-
body = deepcopy_minimal(
1154-
{
1155-
"file": file,
1156-
"file_name": file_name,
1157-
"token": token,
1158-
"checks": checks,
1159-
"custom_coordinates": custom_coordinates,
1160-
"custom_metadata": custom_metadata,
1161-
"description": description,
1162-
"expire": expire,
1163-
"extensions": extensions,
1164-
"folder": folder,
1165-
"is_private_file": is_private_file,
1166-
"is_published": is_published,
1167-
"overwrite_ai_tags": overwrite_ai_tags,
1168-
"overwrite_custom_metadata": overwrite_custom_metadata,
1169-
"overwrite_file": overwrite_file,
1170-
"overwrite_tags": overwrite_tags,
1171-
"public_key": public_key,
1172-
"response_fields": response_fields,
1173-
"signature": signature,
1174-
"tags": tags,
1175-
"transformation": transformation,
1176-
"use_unique_file_name": use_unique_file_name,
1177-
"webhook_url": webhook_url,
1178-
}
1179-
)
1180-
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
11811151
# It should be noted that the actual Content-Type header that will be
11821152
# sent to the server will contain a `boundary` parameter, e.g.
11831153
# multipart/form-data; boundary=---abc--
@@ -1186,8 +1156,34 @@ async def upload(
11861156
"/api/v1/files/upload"
11871157
if self._client._base_url_overridden
11881158
else "https://upload.imagekit.io/api/v1/files/upload",
1189-
body=await async_maybe_transform(body, file_upload_params.FileUploadParams),
1190-
files=files,
1159+
body=await async_maybe_transform(
1160+
{
1161+
"file": file,
1162+
"file_name": file_name,
1163+
"token": token,
1164+
"checks": checks,
1165+
"custom_coordinates": custom_coordinates,
1166+
"custom_metadata": custom_metadata,
1167+
"description": description,
1168+
"expire": expire,
1169+
"extensions": extensions,
1170+
"folder": folder,
1171+
"is_private_file": is_private_file,
1172+
"is_published": is_published,
1173+
"overwrite_ai_tags": overwrite_ai_tags,
1174+
"overwrite_custom_metadata": overwrite_custom_metadata,
1175+
"overwrite_file": overwrite_file,
1176+
"overwrite_tags": overwrite_tags,
1177+
"public_key": public_key,
1178+
"response_fields": response_fields,
1179+
"signature": signature,
1180+
"tags": tags,
1181+
"transformation": transformation,
1182+
"use_unique_file_name": use_unique_file_name,
1183+
"webhook_url": webhook_url,
1184+
},
1185+
file_upload_params.FileUploadParams,
1186+
),
11911187
options=make_request_options(
11921188
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
11931189
),

src/imagekit/types/file_upload_params.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Dict, List, Union, Iterable
66
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict
77

8-
from .._types import FileTypes
98
from .._utils import PropertyInfo
109

1110
__all__ = [
@@ -25,7 +24,7 @@
2524

2625

2726
class FileUploadParams(TypedDict, total=False):
28-
file: Required[FileTypes]
27+
file: Required[str]
2928
"""The API accepts any of the following:
3029
3130
- **Binary data** – send the raw bytes as `multipart/form-data`.

tests/api_resources/test_files.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def test_streaming_response_rename(self, client: ImageKit) -> None:
326326
@parametrize
327327
def test_method_upload(self, client: ImageKit) -> None:
328328
file = client.files.upload(
329-
file=b"raw file contents",
329+
file="https://www.example.com/path/to-image.jpg",
330330
file_name="fileName",
331331
)
332332
assert_matches_type(FileUploadResponse, file, path=["response"])
@@ -335,7 +335,7 @@ def test_method_upload(self, client: ImageKit) -> None:
335335
@parametrize
336336
def test_method_upload_with_all_params(self, client: ImageKit) -> None:
337337
file = client.files.upload(
338-
file=b"raw file contents",
338+
file="https://www.example.com/path/to-image.jpg",
339339
file_name="fileName",
340340
token="token",
341341
checks='"request.folder" : "marketing/"\n',
@@ -397,7 +397,7 @@ def test_method_upload_with_all_params(self, client: ImageKit) -> None:
397397
@parametrize
398398
def test_raw_response_upload(self, client: ImageKit) -> None:
399399
response = client.files.with_raw_response.upload(
400-
file=b"raw file contents",
400+
file="https://www.example.com/path/to-image.jpg",
401401
file_name="fileName",
402402
)
403403

@@ -410,7 +410,7 @@ def test_raw_response_upload(self, client: ImageKit) -> None:
410410
@parametrize
411411
def test_streaming_response_upload(self, client: ImageKit) -> None:
412412
with client.files.with_streaming_response.upload(
413-
file=b"raw file contents",
413+
file="https://www.example.com/path/to-image.jpg",
414414
file_name="fileName",
415415
) as response:
416416
assert not response.is_closed
@@ -729,7 +729,7 @@ async def test_streaming_response_rename(self, async_client: AsyncImageKit) -> N
729729
@parametrize
730730
async def test_method_upload(self, async_client: AsyncImageKit) -> None:
731731
file = await async_client.files.upload(
732-
file=b"raw file contents",
732+
file="https://www.example.com/path/to-image.jpg",
733733
file_name="fileName",
734734
)
735735
assert_matches_type(FileUploadResponse, file, path=["response"])
@@ -738,7 +738,7 @@ async def test_method_upload(self, async_client: AsyncImageKit) -> None:
738738
@parametrize
739739
async def test_method_upload_with_all_params(self, async_client: AsyncImageKit) -> None:
740740
file = await async_client.files.upload(
741-
file=b"raw file contents",
741+
file="https://www.example.com/path/to-image.jpg",
742742
file_name="fileName",
743743
token="token",
744744
checks='"request.folder" : "marketing/"\n',
@@ -800,7 +800,7 @@ async def test_method_upload_with_all_params(self, async_client: AsyncImageKit)
800800
@parametrize
801801
async def test_raw_response_upload(self, async_client: AsyncImageKit) -> None:
802802
response = await async_client.files.with_raw_response.upload(
803-
file=b"raw file contents",
803+
file="https://www.example.com/path/to-image.jpg",
804804
file_name="fileName",
805805
)
806806

@@ -813,7 +813,7 @@ async def test_raw_response_upload(self, async_client: AsyncImageKit) -> None:
813813
@parametrize
814814
async def test_streaming_response_upload(self, async_client: AsyncImageKit) -> None:
815815
async with async_client.files.with_streaming_response.upload(
816-
file=b"raw file contents",
816+
file="https://www.example.com/path/to-image.jpg",
817817
file_name="fileName",
818818
) as response:
819819
assert not response.is_closed

0 commit comments

Comments
 (0)