@@ -50,17 +50,12 @@ import com.imagekit.api.client.ImageKitClient;
50
50
import com.imagekit.api.client.okhttp.ImageKitOkHttpClient ;
51
51
import com.imagekit.api.models.files.FileUploadParams ;
52
52
import com.imagekit.api.models.files.FileUploadResponse ;
53
- import java.io.ByteArrayInputStream ;
54
53
55
54
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
56
55
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
57
56
ImageKitClient client = ImageKitOkHttpClient . fromEnv();
58
57
59
- FileUploadParams params = FileUploadParams . builder()
60
- .file(ByteArrayInputStream(" https://www.example.com/public-url.jpg" . getBytes()))
61
- .fileName(" file-name.jpg" )
62
- .build();
63
- FileUploadResponse response = client. files(). upload(params);
58
+ FileUploadResponse response = client. files(). upload();
64
59
```
65
60
66
61
## Client configuration
@@ -155,18 +150,13 @@ import com.imagekit.api.client.ImageKitClient;
155
150
import com.imagekit.api.client.okhttp.ImageKitOkHttpClient ;
156
151
import com.imagekit.api.models.files.FileUploadParams ;
157
152
import com.imagekit.api.models.files.FileUploadResponse ;
158
- import java.io.ByteArrayInputStream ;
159
153
import java.util.concurrent.CompletableFuture ;
160
154
161
155
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
162
156
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
163
157
ImageKitClient client = ImageKitOkHttpClient . fromEnv();
164
158
165
- FileUploadParams params = FileUploadParams . builder()
166
- .file(ByteArrayInputStream(" https://www.example.com/public-url.jpg" . getBytes()))
167
- .fileName(" file-name.jpg" )
168
- .build();
169
- CompletableFuture<FileUploadResponse > response = client. async(). files(). upload(params);
159
+ CompletableFuture<FileUploadResponse > response = client. async(). files(). upload();
170
160
```
171
161
172
162
Or create an asynchronous client from the beginning:
@@ -176,18 +166,13 @@ import com.imagekit.api.client.ImageKitClientAsync;
176
166
import com.imagekit.api.client.okhttp.ImageKitOkHttpClientAsync ;
177
167
import com.imagekit.api.models.files.FileUploadParams ;
178
168
import com.imagekit.api.models.files.FileUploadResponse ;
179
- import java.io.ByteArrayInputStream ;
180
169
import java.util.concurrent.CompletableFuture ;
181
170
182
171
// Configures using the `imagekit.imagekitPrivateApiKey`, `imagekit.optionalImagekitIgnoresThis`, `imagekit.imagekitWebhookSecret` and `imagekit.baseUrl` system properties
183
172
// Or configures using the `IMAGEKIT_PRIVATE_API_KEY`, `OPTIONAL_IMAGEKIT_IGNORES_THIS`, `IMAGEKIT_WEBHOOK_SECRET` and `IMAGE_KIT_BASE_URL` environment variables
184
173
ImageKitClientAsync client = ImageKitOkHttpClientAsync . fromEnv();
185
174
186
- FileUploadParams params = FileUploadParams . builder()
187
- .file(ByteArrayInputStream(" https://www.example.com/public-url.jpg" . getBytes()))
188
- .fileName(" file-name.jpg" )
189
- .build();
190
- CompletableFuture<FileUploadResponse > response = client. files(). upload(params);
175
+ CompletableFuture<FileUploadResponse > response = client. files(). upload();
191
176
```
192
177
193
178
The asynchronous client supports the same options as the synchronous one, except most methods return ` CompletableFuture ` s.
@@ -199,50 +184,50 @@ The SDK defines methods that accept files.
199
184
To upload a file, pass a [ ` Path ` ] ( https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html ) :
200
185
201
186
``` java
202
- import com.imagekit.api.models.files.FileUploadParams ;
203
- import com.imagekit.api.models.files.FileUploadResponse ;
187
+ import com.imagekit.api.models.beta.v2. files.FileUploadParams ;
188
+ import com.imagekit.api.models.beta.v2. files.FileUploadResponse ;
204
189
import java.nio.file.Paths ;
205
190
206
191
FileUploadParams params = FileUploadParams . builder()
207
192
.fileName(" fileName" )
208
193
.file(Paths . get(" /path/to/file" ))
209
194
.build();
210
- FileUploadResponse response = client. files(). upload(params);
195
+ FileUploadResponse response = client. beta() . v2() . files(). upload(params);
211
196
```
212
197
213
198
Or an arbitrary [ ` InputStream ` ] ( https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html ) :
214
199
215
200
``` java
216
- import com.imagekit.api.models.files.FileUploadParams ;
217
- import com.imagekit.api.models.files.FileUploadResponse ;
201
+ import com.imagekit.api.models.beta.v2. files.FileUploadParams ;
202
+ import com.imagekit.api.models.beta.v2. files.FileUploadResponse ;
218
203
import java.net.URL ;
219
204
220
205
FileUploadParams params = FileUploadParams . builder()
221
206
.fileName(" fileName" )
222
207
.file(new URL (" https://example.com//path/to/file" ). openStream())
223
208
.build();
224
- FileUploadResponse response = client. files(). upload(params);
209
+ FileUploadResponse response = client. beta() . v2() . files(). upload(params);
225
210
```
226
211
227
212
Or a ` byte[] ` array:
228
213
229
214
``` java
230
- import com.imagekit.api.models.files.FileUploadParams ;
231
- import com.imagekit.api.models.files.FileUploadResponse ;
215
+ import com.imagekit.api.models.beta.v2. files.FileUploadParams ;
216
+ import com.imagekit.api.models.beta.v2. files.FileUploadResponse ;
232
217
233
218
FileUploadParams params = FileUploadParams . builder()
234
219
.fileName(" fileName" )
235
220
.file(" content" . getBytes())
236
221
.build();
237
- FileUploadResponse response = client. files(). upload(params);
222
+ FileUploadResponse response = client. beta() . v2() . files(). upload(params);
238
223
```
239
224
240
225
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 ) :
241
226
242
227
``` java
243
228
import com.imagekit.api.core.MultipartField ;
244
- import com.imagekit.api.models.files.FileUploadParams ;
245
- import com.imagekit.api.models.files.FileUploadResponse ;
229
+ import com.imagekit.api.models.beta.v2. files.FileUploadParams ;
230
+ import com.imagekit.api.models.beta.v2. files.FileUploadResponse ;
246
231
import java.io.InputStream ;
247
232
import java.net.URL ;
248
233
@@ -253,7 +238,7 @@ FileUploadParams params = FileUploadParams.builder()
253
238
.filename(" /path/to/file" )
254
239
.build())
255
240
.build();
256
- FileUploadResponse response = client. files(). upload(params);
241
+ FileUploadResponse response = client. beta() . v2() . files(). upload(params);
257
242
```
258
243
259
244
## Raw responses
@@ -267,13 +252,8 @@ import com.imagekit.api.core.http.Headers;
267
252
import com.imagekit.api.core.http.HttpResponseFor ;
268
253
import com.imagekit.api.models.files.FileUploadParams ;
269
254
import com.imagekit.api.models.files.FileUploadResponse ;
270
- import java.io.ByteArrayInputStream ;
271
255
272
- FileUploadParams params = FileUploadParams . builder()
273
- .file(ByteArrayInputStream(" https://www.example.com/public-url.jpg" . getBytes()))
274
- .fileName(" file-name.jpg" )
275
- .build();
276
- HttpResponseFor<FileUploadResponse > response = client. files(). withRawResponse(). upload(params);
256
+ HttpResponseFor<FileUploadResponse > response = client. files(). withRawResponse(). upload();
277
257
278
258
int statusCode = response. statusCode();
279
259
Headers headers = response. headers();
@@ -382,9 +362,7 @@ To set a custom timeout, configure the method call using the `timeout` method:
382
362
``` java
383
363
import com.imagekit.api.models.files.FileUploadResponse ;
384
364
385
- FileUploadResponse response = client. files(). upload(
386
- params, RequestOptions . builder(). timeout(Duration . ofSeconds(30 )). build()
387
- );
365
+ FileUploadResponse response = client. files(). upload(RequestOptions . builder(). timeout(Duration . ofSeconds(30 )). build());
388
366
```
389
367
390
368
Or configure the default for all method calls at the client level:
@@ -502,10 +480,10 @@ To set undocumented parameters on _nested_ headers, query params, or body classe
502
480
503
481
``` java
504
482
import com.imagekit.api.core.JsonValue ;
505
- import com.imagekit.api.models.files.FileUploadParams ;
483
+ import com.imagekit.api.models.custommetadatafields.CustomMetadataFieldCreateParams ;
506
484
507
- FileUploadParams params = FileUploadParams . builder()
508
- .transformation( FileUploadParams . Transformation . builder()
485
+ CustomMetadataFieldCreateParams params = CustomMetadataFieldCreateParams . builder()
486
+ .schema( CustomMetadataFieldCreateParams . Schema . builder()
509
487
.putAdditionalProperty(" secretProperty" , JsonValue . from(" 42" ))
510
488
.build())
511
489
.build();
@@ -516,13 +494,9 @@ These properties can be accessed on the nested built object later using the `_ad
516
494
To set a documented parameter or property to an undocumented or not yet supported _ value_ , pass a [ ` JsonValue ` ] ( image-kit-java-core/src/main/kotlin/com/imagekit/api/core/Values.kt ) object to its setter:
517
495
518
496
``` java
519
- import com.imagekit.api.core.JsonValue ;
520
497
import com.imagekit.api.models.files.FileUploadParams ;
521
498
522
- FileUploadParams params = FileUploadParams . builder()
523
- .file(JsonValue . from(42 ))
524
- .fileName(" file-name.jpg" )
525
- .build();
499
+ FileUploadParams params = FileUploadParams . builder(). build();
526
500
```
527
501
528
502
The most straightforward way to create a [ ` JsonValue ` ] ( image-kit-java-core/src/main/kotlin/com/imagekit/api/core/Values.kt ) is using its ` from(...) ` method:
@@ -570,11 +544,15 @@ To forcibly omit a required parameter or property, pass [`JsonMissing`](image-ki
570
544
571
545
``` java
572
546
import com.imagekit.api.core.JsonMissing ;
547
+ import com.imagekit.api.models.custommetadatafields.CustomMetadataFieldCreateParams ;
573
548
import com.imagekit.api.models.files.FileUploadParams ;
574
549
575
- FileUploadParams params = FileUploadParams . builder()
576
- .fileName(" fileName" )
577
- .file(JsonMissing . of())
550
+ FileUploadParams params = CustomMetadataFieldCreateParams . builder()
551
+ .name(" price" )
552
+ .schema(CustomMetadataFieldCreateParams . Schema . builder()
553
+ .type(CustomMetadataFieldCreateParams . Schema . Type . NUMBER )
554
+ .build())
555
+ .label(JsonMissing . of())
578
556
.build();
579
557
```
580
558
@@ -614,22 +592,21 @@ To access a property's raw JSON value, which may be undocumented, call its `_` p
614
592
615
593
``` java
616
594
import com.imagekit.api.core.JsonField ;
617
- import java.io.InputStream ;
618
595
import java.util.Optional ;
619
596
620
- JsonField<InputStream > file = client. files(). upload(params). _file ();
597
+ JsonField<Object > field = client. files(). upload(params). _field ();
621
598
622
- if (file . isMissing()) {
599
+ if (field . isMissing()) {
623
600
// The property is absent from the JSON response
624
- } else if (file . isNull()) {
601
+ } else if (field . isNull()) {
625
602
// The property was set to literal null
626
603
} else {
627
604
// Check if value was provided as a string
628
605
// Other methods include `asNumber()`, `asBoolean()`, etc.
629
- Optional<String > jsonString = file . asString();
606
+ Optional<String > jsonString = field . asString();
630
607
631
608
// Try to deserialize into a custom type
632
- MyClass myObject = file . asUnknown(). orElseThrow(). convert(MyClass . class);
609
+ MyClass myObject = field . asUnknown(). orElseThrow(). convert(MyClass . class);
633
610
}
634
611
```
635
612
@@ -652,9 +629,7 @@ Or configure the method call to validate the response using the `responseValidat
652
629
``` java
653
630
import com.imagekit.api.models.files.FileUploadResponse ;
654
631
655
- FileUploadResponse response = client. files(). upload(
656
- params, RequestOptions . builder(). responseValidation(true ). build()
657
- );
632
+ FileUploadResponse response = client. files(). upload(RequestOptions . builder(). responseValidation(true ). build());
658
633
```
659
634
660
635
Or configure the default for all method calls at the client level:
0 commit comments