Skip to content

Commit 74027ef

Browse files
feat(api): manual updates
1 parent 76c5b5e commit 74027ef

File tree

8 files changed

+123
-59
lines changed

8 files changed

+123
-59
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-911102f2eaf3be4b34381f6ba089330bed099bb72eb93667ce2f6e72b5934c8c.yml
3-
openapi_spec_hash: 637ad417a580137914441bd790b04cc2
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-0726d89b19f532c7fb92990d688a9bfb5aa4a9a871d64f49d4ba45bac6998e4a.yml
3+
openapi_spec_hash: 9525bb02ab496b3459a1f93ac50968e3
44
config_hash: 70f9408b8d1dfbcf262a20d6eed50e1c

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ import com.imagekit.api.client.ImageKitClient;
5050
import com.imagekit.api.client.okhttp.ImageKitOkHttpClient;
5151
import com.imagekit.api.models.files.FileUploadParams;
5252
import com.imagekit.api.models.files.FileUploadResponse;
53+
import java.io.ByteArrayInputStream;
5354

5455
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
5556
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
5657
ImageKitClient client = ImageKitOkHttpClient.fromEnv();
5758

5859
FileUploadParams params = FileUploadParams.builder()
59-
.file("https://www.example.com/public-url.jpg")
60+
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
6061
.fileName("file-name.jpg")
6162
.build();
6263
FileUploadResponse response = client.files().upload(params);
@@ -154,14 +155,15 @@ import com.imagekit.api.client.ImageKitClient;
154155
import com.imagekit.api.client.okhttp.ImageKitOkHttpClient;
155156
import com.imagekit.api.models.files.FileUploadParams;
156157
import com.imagekit.api.models.files.FileUploadResponse;
158+
import java.io.ByteArrayInputStream;
157159
import java.util.concurrent.CompletableFuture;
158160

159161
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
160162
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
161163
ImageKitClient client = ImageKitOkHttpClient.fromEnv();
162164

163165
FileUploadParams params = FileUploadParams.builder()
164-
.file("https://www.example.com/public-url.jpg")
166+
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
165167
.fileName("file-name.jpg")
166168
.build();
167169
CompletableFuture<FileUploadResponse> response = client.async().files().upload(params);
@@ -174,14 +176,15 @@ import com.imagekit.api.client.ImageKitClientAsync;
174176
import com.imagekit.api.client.okhttp.ImageKitOkHttpClientAsync;
175177
import com.imagekit.api.models.files.FileUploadParams;
176178
import com.imagekit.api.models.files.FileUploadResponse;
179+
import java.io.ByteArrayInputStream;
177180
import java.util.concurrent.CompletableFuture;
178181

179182
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
180183
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
181184
ImageKitClientAsync client = ImageKitOkHttpClientAsync.fromEnv();
182185

183186
FileUploadParams params = FileUploadParams.builder()
184-
.file("https://www.example.com/public-url.jpg")
187+
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
185188
.fileName("file-name.jpg")
186189
.build();
187190
CompletableFuture<FileUploadResponse> response = client.files().upload(params);
@@ -196,50 +199,50 @@ The SDK defines methods that accept files.
196199
To upload a file, pass a [`Path`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html):
197200

198201
```java
199-
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
200-
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
202+
import com.imagekit.api.models.files.FileUploadParams;
203+
import com.imagekit.api.models.files.FileUploadResponse;
201204
import java.nio.file.Paths;
202205

203206
FileUploadParams params = FileUploadParams.builder()
204207
.fileName("fileName")
205208
.file(Paths.get("/path/to/file"))
206209
.build();
207-
FileUploadResponse response = client.beta().v2().files().upload(params);
210+
FileUploadResponse response = client.files().upload(params);
208211
```
209212

210213
Or an arbitrary [`InputStream`](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html):
211214

212215
```java
213-
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
214-
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
216+
import com.imagekit.api.models.files.FileUploadParams;
217+
import com.imagekit.api.models.files.FileUploadResponse;
215218
import java.net.URL;
216219

217220
FileUploadParams params = FileUploadParams.builder()
218221
.fileName("fileName")
219222
.file(new URL("https://example.com//path/to/file").openStream())
220223
.build();
221-
FileUploadResponse response = client.beta().v2().files().upload(params);
224+
FileUploadResponse response = client.files().upload(params);
222225
```
223226

224227
Or a `byte[]` array:
225228

226229
```java
227-
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
228-
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
230+
import com.imagekit.api.models.files.FileUploadParams;
231+
import com.imagekit.api.models.files.FileUploadResponse;
229232

230233
FileUploadParams params = FileUploadParams.builder()
231234
.fileName("fileName")
232235
.file("content".getBytes())
233236
.build();
234-
FileUploadResponse response = client.beta().v2().files().upload(params);
237+
FileUploadResponse response = client.files().upload(params);
235238
```
236239

237240
Note that when passing a non-`Path` its filename is unknown so it will not be included in the request. To manually set a filename, pass a [`MultipartField`](image-kit-java-core/src/main/kotlin/com/imagekit/api/core/Values.kt):
238241

239242
```java
240243
import com.imagekit.api.core.MultipartField;
241-
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
242-
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
244+
import com.imagekit.api.models.files.FileUploadParams;
245+
import com.imagekit.api.models.files.FileUploadResponse;
243246
import java.io.InputStream;
244247
import java.net.URL;
245248

@@ -250,7 +253,7 @@ FileUploadParams params = FileUploadParams.builder()
250253
.filename("/path/to/file")
251254
.build())
252255
.build();
253-
FileUploadResponse response = client.beta().v2().files().upload(params);
256+
FileUploadResponse response = client.files().upload(params);
254257
```
255258

256259
## Raw responses
@@ -264,9 +267,10 @@ import com.imagekit.api.core.http.Headers;
264267
import com.imagekit.api.core.http.HttpResponseFor;
265268
import com.imagekit.api.models.files.FileUploadParams;
266269
import com.imagekit.api.models.files.FileUploadResponse;
270+
import java.io.ByteArrayInputStream;
267271

268272
FileUploadParams params = FileUploadParams.builder()
269-
.file("https://www.example.com/public-url.jpg")
273+
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
270274
.fileName("file-name.jpg")
271275
.build();
272276
HttpResponseFor<FileUploadResponse> response = client.files().withRawResponse().upload(params);
@@ -610,9 +614,10 @@ To access a property's raw JSON value, which may be undocumented, call its `_` p
610614

611615
```java
612616
import com.imagekit.api.core.JsonField;
617+
import java.io.InputStream;
613618
import java.util.Optional;
614619

615-
JsonField<String> file = client.files().upload(params)._file();
620+
JsonField<InputStream> file = client.files().upload(params)._file();
616621

617622
if (file.isMissing()) {
618623
// The property is absent from the JSON response

image-kit-java-core/src/main/kotlin/com/imagekit/api/models/files/FileUploadParams.kt

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ import com.imagekit.api.core.http.Headers
2828
import com.imagekit.api.core.http.QueryParams
2929
import com.imagekit.api.core.toImmutable
3030
import com.imagekit.api.errors.ImageKitInvalidDataException
31+
import java.io.InputStream
32+
import java.nio.file.Path
3133
import java.util.Collections
3234
import java.util.Objects
3335
import java.util.Optional
36+
import kotlin.io.path.inputStream
37+
import kotlin.io.path.name
3438
import kotlin.jvm.optionals.getOrNull
3539

3640
/**
@@ -74,7 +78,7 @@ private constructor(
7478
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type or is
7579
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
7680
*/
77-
fun file(): String = body.file()
81+
fun file(): InputStream = body.file()
7882

7983
/**
8084
* The name with which the file has to be uploaded. The file name can contain:
@@ -323,7 +327,7 @@ private constructor(
323327
*
324328
* Unlike [file], this method doesn't throw if the multipart field has an unexpected type.
325329
*/
326-
fun _file(): MultipartField<String> = body._file()
330+
fun _file(): MultipartField<InputStream> = body._file()
327331

328332
/**
329333
* Returns the raw multipart value of [fileName].
@@ -552,15 +556,38 @@ private constructor(
552556
* When supplying a URL, the server must receive the response headers within 8 seconds;
553557
* otherwise the request fails with 400 Bad Request.
554558
*/
555-
fun file(file: String) = apply { body.file(file) }
559+
fun file(file: InputStream) = apply { body.file(file) }
556560

557561
/**
558562
* Sets [Builder.file] to an arbitrary multipart value.
559563
*
560-
* You should usually call [Builder.file] with a well-typed [String] value instead. This
561-
* method is primarily for setting the field to an undocumented or not yet supported value.
564+
* You should usually call [Builder.file] with a well-typed [InputStream] value instead.
565+
* This method is primarily for setting the field to an undocumented or not yet supported
566+
* value.
567+
*/
568+
fun file(file: MultipartField<InputStream>) = apply { body.file(file) }
569+
570+
/**
571+
* The API accepts any of the following:
572+
* - **Binary data** – send the raw bytes as `multipart/form-data`.
573+
* - **HTTP / HTTPS URL** – a publicly reachable URL that ImageKit’s servers can fetch.
574+
* - **Base64 string** – the file encoded as a Base64 data URI or plain Base64.
575+
*
576+
* When supplying a URL, the server must receive the response headers within 8 seconds;
577+
* otherwise the request fails with 400 Bad Request.
578+
*/
579+
fun file(file: ByteArray) = apply { body.file(file) }
580+
581+
/**
582+
* The API accepts any of the following:
583+
* - **Binary data** – send the raw bytes as `multipart/form-data`.
584+
* - **HTTP / HTTPS URL** – a publicly reachable URL that ImageKit’s servers can fetch.
585+
* - **Base64 string** – the file encoded as a Base64 data URI or plain Base64.
586+
*
587+
* When supplying a URL, the server must receive the response headers within 8 seconds;
588+
* otherwise the request fails with 400 Bad Request.
562589
*/
563-
fun file(file: MultipartField<String>) = apply { body.file(file) }
590+
fun file(path: Path) = apply { body.file(path) }
564591

565592
/**
566593
* The name with which the file has to be uploaded. The file name can contain:
@@ -1170,7 +1197,7 @@ private constructor(
11701197

11711198
class Body
11721199
private constructor(
1173-
private val file: MultipartField<String>,
1200+
private val file: MultipartField<InputStream>,
11741201
private val fileName: MultipartField<String>,
11751202
private val token: MultipartField<String>,
11761203
private val checks: MultipartField<String>,
@@ -1208,7 +1235,7 @@ private constructor(
12081235
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type or is
12091236
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
12101237
*/
1211-
fun file(): String = file.value.getRequired("file")
1238+
fun file(): InputStream = file.value.getRequired("file")
12121239

12131240
/**
12141241
* The name with which the file has to be uploaded. The file name can contain:
@@ -1465,7 +1492,7 @@ private constructor(
14651492
*
14661493
* Unlike [file], this method doesn't throw if the multipart field has an unexpected type.
14671494
*/
1468-
@JsonProperty("file") @ExcludeMissing fun _file(): MultipartField<String> = file
1495+
@JsonProperty("file") @ExcludeMissing fun _file(): MultipartField<InputStream> = file
14691496

14701497
/**
14711498
* Returns the raw multipart value of [fileName].
@@ -1699,7 +1726,7 @@ private constructor(
16991726
/** A builder for [Body]. */
17001727
class Builder internal constructor() {
17011728

1702-
private var file: MultipartField<String>? = null
1729+
private var file: MultipartField<InputStream>? = null
17031730
private var fileName: MultipartField<String>? = null
17041731
private var token: MultipartField<String> = MultipartField.of(null)
17051732
private var checks: MultipartField<String> = MultipartField.of(null)
@@ -1761,16 +1788,44 @@ private constructor(
17611788
* When supplying a URL, the server must receive the response headers within 8 seconds;
17621789
* otherwise the request fails with 400 Bad Request.
17631790
*/
1764-
fun file(file: String) = file(MultipartField.of(file))
1791+
fun file(file: InputStream) = file(MultipartField.of(file))
17651792

17661793
/**
17671794
* Sets [Builder.file] to an arbitrary multipart value.
17681795
*
1769-
* You should usually call [Builder.file] with a well-typed [String] value instead. This
1770-
* method is primarily for setting the field to an undocumented or not yet supported
1771-
* value.
1796+
* You should usually call [Builder.file] with a well-typed [InputStream] value instead.
1797+
* This method is primarily for setting the field to an undocumented or not yet
1798+
* supported value.
1799+
*/
1800+
fun file(file: MultipartField<InputStream>) = apply { this.file = file }
1801+
1802+
/**
1803+
* The API accepts any of the following:
1804+
* - **Binary data** – send the raw bytes as `multipart/form-data`.
1805+
* - **HTTP / HTTPS URL** – a publicly reachable URL that ImageKit’s servers can fetch.
1806+
* - **Base64 string** – the file encoded as a Base64 data URI or plain Base64.
1807+
*
1808+
* When supplying a URL, the server must receive the response headers within 8 seconds;
1809+
* otherwise the request fails with 400 Bad Request.
1810+
*/
1811+
fun file(file: ByteArray) = file(file.inputStream())
1812+
1813+
/**
1814+
* The API accepts any of the following:
1815+
* - **Binary data** – send the raw bytes as `multipart/form-data`.
1816+
* - **HTTP / HTTPS URL** – a publicly reachable URL that ImageKit’s servers can fetch.
1817+
* - **Base64 string** – the file encoded as a Base64 data URI or plain Base64.
1818+
*
1819+
* When supplying a URL, the server must receive the response headers within 8 seconds;
1820+
* otherwise the request fails with 400 Bad Request.
17721821
*/
1773-
fun file(file: MultipartField<String>) = apply { this.file = file }
1822+
fun file(path: Path) =
1823+
file(
1824+
MultipartField.builder<InputStream>()
1825+
.value(path.inputStream())
1826+
.filename(path.name)
1827+
.build()
1828+
)
17741829

17751830
/**
17761831
* The name with which the file has to be uploaded. The file name can contain:

image-kit-java-core/src/test/kotlin/com/imagekit/api/models/files/FileUploadParamsTest.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class FileUploadParamsTest {
1313
@Test
1414
fun create() {
1515
FileUploadParams.builder()
16-
.file("file")
16+
.file("some content".byteInputStream())
1717
.fileName("fileName")
1818
.token("token")
1919
.checks("\"request.folder\" : \"marketing/\"\n")
@@ -95,7 +95,7 @@ internal class FileUploadParamsTest {
9595
fun body() {
9696
val params =
9797
FileUploadParams.builder()
98-
.file("file")
98+
.file("some content".byteInputStream())
9999
.fileName("fileName")
100100
.token("token")
101101
.checks("\"request.folder\" : \"marketing/\"\n")
@@ -184,7 +184,7 @@ internal class FileUploadParamsTest {
184184
)
185185
.isEqualTo(
186186
mapOf(
187-
"file" to MultipartField.of("file"),
187+
"file" to MultipartField.of("some content".byteInputStream()),
188188
"fileName" to MultipartField.of("fileName"),
189189
"token" to MultipartField.of("token"),
190190
"checks" to MultipartField.of("\"request.folder\" : \"marketing/\"\n"),
@@ -276,7 +276,11 @@ internal class FileUploadParamsTest {
276276

277277
@Test
278278
fun bodyWithoutOptionalFields() {
279-
val params = FileUploadParams.builder().file("file").fileName("fileName").build()
279+
val params =
280+
FileUploadParams.builder()
281+
.file("some content".byteInputStream())
282+
.fileName("fileName")
283+
.build()
280284

281285
val body = params._body()
282286

@@ -290,7 +294,7 @@ internal class FileUploadParamsTest {
290294
)
291295
.isEqualTo(
292296
mapOf(
293-
"file" to MultipartField.of("file"),
297+
"file" to MultipartField.of("some content".byteInputStream()),
294298
"fileName" to MultipartField.of("fileName"),
295299
)
296300
.mapValues { (_, field) ->

0 commit comments

Comments
 (0)