Skip to content

Commit b462410

Browse files
feat(api): manual updates
1 parent 436b4f8 commit b462410

File tree

8 files changed

+59
-119
lines changed

8 files changed

+59
-119
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: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ 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;
5453

5554
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
5655
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
5756
ImageKitClient client = ImageKitOkHttpClient.fromEnv();
5857

5958
FileUploadParams params = FileUploadParams.builder()
60-
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
59+
.file("https://www.example.com/public-url.jpg")
6160
.fileName("file-name.jpg")
6261
.build();
6362
FileUploadResponse response = client.files().upload(params);
@@ -155,15 +154,14 @@ import com.imagekit.api.client.ImageKitClient;
155154
import com.imagekit.api.client.okhttp.ImageKitOkHttpClient;
156155
import com.imagekit.api.models.files.FileUploadParams;
157156
import com.imagekit.api.models.files.FileUploadResponse;
158-
import java.io.ByteArrayInputStream;
159157
import java.util.concurrent.CompletableFuture;
160158

161159
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
162160
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
163161
ImageKitClient client = ImageKitOkHttpClient.fromEnv();
164162

165163
FileUploadParams params = FileUploadParams.builder()
166-
.file(ByteArrayInputStream("https://www.example.com/public-url.jpg".getBytes()))
164+
.file("https://www.example.com/public-url.jpg")
167165
.fileName("file-name.jpg")
168166
.build();
169167
CompletableFuture<FileUploadResponse> response = client.async().files().upload(params);
@@ -176,15 +174,14 @@ import com.imagekit.api.client.ImageKitClientAsync;
176174
import com.imagekit.api.client.okhttp.ImageKitOkHttpClientAsync;
177175
import com.imagekit.api.models.files.FileUploadParams;
178176
import com.imagekit.api.models.files.FileUploadResponse;
179-
import java.io.ByteArrayInputStream;
180177
import java.util.concurrent.CompletableFuture;
181178

182179
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
183180
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
184181
ImageKitClientAsync client = ImageKitOkHttpClientAsync.fromEnv();
185182

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

201198
```java
202-
import com.imagekit.api.models.files.FileUploadParams;
203-
import com.imagekit.api.models.files.FileUploadResponse;
199+
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
200+
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
204201
import java.nio.file.Paths;
205202

206203
FileUploadParams params = FileUploadParams.builder()
207204
.fileName("fileName")
208205
.file(Paths.get("/path/to/file"))
209206
.build();
210-
FileUploadResponse response = client.files().upload(params);
207+
FileUploadResponse response = client.beta().v2().files().upload(params);
211208
```
212209

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

215212
```java
216-
import com.imagekit.api.models.files.FileUploadParams;
217-
import com.imagekit.api.models.files.FileUploadResponse;
213+
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
214+
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
218215
import java.net.URL;
219216

220217
FileUploadParams params = FileUploadParams.builder()
221218
.fileName("fileName")
222219
.file(new URL("https://example.com//path/to/file").openStream())
223220
.build();
224-
FileUploadResponse response = client.files().upload(params);
221+
FileUploadResponse response = client.beta().v2().files().upload(params);
225222
```
226223

227224
Or a `byte[]` array:
228225

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

233230
FileUploadParams params = FileUploadParams.builder()
234231
.fileName("fileName")
235232
.file("content".getBytes())
236233
.build();
237-
FileUploadResponse response = client.files().upload(params);
234+
FileUploadResponse response = client.beta().v2().files().upload(params);
238235
```
239236

240237
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):
241238

242239
```java
243240
import com.imagekit.api.core.MultipartField;
244-
import com.imagekit.api.models.files.FileUploadParams;
245-
import com.imagekit.api.models.files.FileUploadResponse;
241+
import com.imagekit.api.models.beta.v2.files.FileUploadParams;
242+
import com.imagekit.api.models.beta.v2.files.FileUploadResponse;
246243
import java.io.InputStream;
247244
import java.net.URL;
248245

@@ -253,7 +250,7 @@ FileUploadParams params = FileUploadParams.builder()
253250
.filename("/path/to/file")
254251
.build())
255252
.build();
256-
FileUploadResponse response = client.files().upload(params);
253+
FileUploadResponse response = client.beta().v2().files().upload(params);
257254
```
258255

259256
## Raw responses
@@ -267,10 +264,9 @@ import com.imagekit.api.core.http.Headers;
267264
import com.imagekit.api.core.http.HttpResponseFor;
268265
import com.imagekit.api.models.files.FileUploadParams;
269266
import com.imagekit.api.models.files.FileUploadResponse;
270-
import java.io.ByteArrayInputStream;
271267

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

615611
```java
616612
import com.imagekit.api.core.JsonField;
617-
import java.io.InputStream;
618613
import java.util.Optional;
619614

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

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

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

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ 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
3331
import java.util.Collections
3432
import java.util.Objects
3533
import java.util.Optional
36-
import kotlin.io.path.inputStream
37-
import kotlin.io.path.name
3834
import kotlin.jvm.optionals.getOrNull
3935

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

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

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

561557
/**
562558
* Sets [Builder.file] to an arbitrary multipart value.
563559
*
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.
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.
589562
*/
590-
fun file(path: Path) = apply { body.file(path) }
563+
fun file(file: MultipartField<String>) = apply { body.file(file) }
591564

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

11981171
class Body
11991172
private constructor(
1200-
private val file: MultipartField<InputStream>,
1173+
private val file: MultipartField<String>,
12011174
private val fileName: MultipartField<String>,
12021175
private val token: MultipartField<String>,
12031176
private val checks: MultipartField<String>,
@@ -1235,7 +1208,7 @@ private constructor(
12351208
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type or is
12361209
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
12371210
*/
1238-
fun file(): InputStream = file.value.getRequired("file")
1211+
fun file(): String = file.value.getRequired("file")
12391212

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

14971470
/**
14981471
* Returns the raw multipart value of [fileName].
@@ -1726,7 +1699,7 @@ private constructor(
17261699
/** A builder for [Body]. */
17271700
class Builder internal constructor() {
17281701

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

17931766
/**
17941767
* Sets [Builder.file] to an arbitrary multipart value.
17951768
*
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.
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.
18211772
*/
1822-
fun file(path: Path) =
1823-
file(
1824-
MultipartField.builder<InputStream>()
1825-
.value(path.inputStream())
1826-
.filename(path.name)
1827-
.build()
1828-
)
1773+
fun file(file: MultipartField<String>) = apply { this.file = file }
18291774

18301775
/**
18311776
* 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: 5 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("some content".byteInputStream())
16+
.file("https://www.example.com/path/to-image.jpg")
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("some content".byteInputStream())
98+
.file("https://www.example.com/path/to-image.jpg")
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("some content".byteInputStream()),
187+
"file" to MultipartField.of("https://www.example.com/path/to-image.jpg"),
188188
"fileName" to MultipartField.of("fileName"),
189189
"token" to MultipartField.of("token"),
190190
"checks" to MultipartField.of("\"request.folder\" : \"marketing/\"\n"),
@@ -278,7 +278,7 @@ internal class FileUploadParamsTest {
278278
fun bodyWithoutOptionalFields() {
279279
val params =
280280
FileUploadParams.builder()
281-
.file("some content".byteInputStream())
281+
.file("https://www.example.com/path/to-image.jpg")
282282
.fileName("fileName")
283283
.build()
284284

@@ -294,7 +294,7 @@ internal class FileUploadParamsTest {
294294
)
295295
.isEqualTo(
296296
mapOf(
297-
"file" to MultipartField.of("some content".byteInputStream()),
297+
"file" to MultipartField.of("https://www.example.com/path/to-image.jpg"),
298298
"fileName" to MultipartField.of("fileName"),
299299
)
300300
.mapValues { (_, field) ->

0 commit comments

Comments
 (0)