@@ -31,7 +31,7 @@ const client = new ImageKit({
31
31
});
32
32
33
33
const response = await client .files .upload ({
34
- file: ' https://www.example.com/public-url.jpg ' ,
34
+ file: fs . createReadStream ( ' path/to/file ' ) ,
35
35
fileName: ' file-name.jpg' ,
36
36
});
37
37
@@ -52,7 +52,7 @@ const client = new ImageKit({
52
52
});
53
53
54
54
const params: ImageKit .FileUploadParams = {
55
- file: ' https://www.example.com/public-url.jpg ' ,
55
+ file: fs . createReadStream ( ' path/to/file ' ) ,
56
56
fileName: ' file-name.jpg' ,
57
57
};
58
58
const response: ImageKit .FileUploadResponse = await client .files .upload (params );
@@ -76,23 +76,17 @@ import ImageKit, { toFile } from '@imagekit/nodejs';
76
76
const client = new ImageKit ();
77
77
78
78
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
79
- await client .beta . v2 . files .upload ({ file: fs .createReadStream (' /path/to/file' ), fileName: ' fileName' });
79
+ await client .files .upload ({ file: fs .createReadStream (' /path/to/file' ), fileName: ' fileName' });
80
80
81
81
// Or if you have the web `File` API you can pass a `File` instance:
82
- await client .beta . v2 . files .upload ({ file: new File ([' my bytes' ], ' file' ), fileName: ' fileName' });
82
+ await client .files .upload ({ file: new File ([' my bytes' ], ' file' ), fileName: ' fileName' });
83
83
84
84
// You can also pass a `fetch` `Response`:
85
- await client .beta . v2 . files .upload ({ file: await fetch (' https://somesite/file' ), fileName: ' fileName' });
85
+ await client .files .upload ({ file: await fetch (' https://somesite/file' ), fileName: ' fileName' });
86
86
87
87
// Finally, if none of the above are convenient, you can use our `toFile` helper:
88
- await client .beta .v2 .files .upload ({
89
- file: await toFile (Buffer .from (' my bytes' ), ' file' ),
90
- fileName: ' fileName' ,
91
- });
92
- await client .beta .v2 .files .upload ({
93
- file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ),
94
- fileName: ' fileName' ,
95
- });
88
+ await client .files .upload ({ file: await toFile (Buffer .from (' my bytes' ), ' file' ), fileName: ' fileName' });
89
+ await client .files .upload ({ file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ), fileName: ' fileName' });
96
90
```
97
91
98
92
## URL generation
@@ -301,7 +295,7 @@ a subclass of `APIError` will be thrown:
301
295
<!-- prettier-ignore -->
302
296
``` ts
303
297
const response = await client .files
304
- .upload ({ file: ' https://www.example.com/public-url.jpg ' , fileName: ' file-name.jpg' })
298
+ .upload ({ file: fs . createReadStream ( ' path/to/file ' ) , fileName: ' file-name.jpg' })
305
299
.catch (async (err ) => {
306
300
if (err instanceof ImageKit .APIError ) {
307
301
console .log (err .status ); // 400
@@ -342,7 +336,7 @@ const client = new ImageKit({
342
336
});
343
337
344
338
// Or, configure per-request:
345
- await client .files .upload ({ file: ' https://www.example.com/public-url.jpg ' , fileName: ' file-name.jpg' }, {
339
+ await client .files .upload ({ file: fs . createReadStream ( ' path/to/file ' ) , fileName: ' file-name.jpg' }, {
346
340
maxRetries: 5 ,
347
341
});
348
342
```
@@ -359,7 +353,7 @@ const client = new ImageKit({
359
353
});
360
354
361
355
// Override per-request:
362
- await client .files .upload ({ file: ' https://www.example.com/public-url.jpg ' , fileName: ' file-name.jpg' }, {
356
+ await client .files .upload ({ file: fs . createReadStream ( ' path/to/file ' ) , fileName: ' file-name.jpg' }, {
363
357
timeout: 5 * 1000 ,
364
358
});
365
359
```
@@ -383,13 +377,13 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
383
377
const client = new ImageKit ();
384
378
385
379
const response = await client .files
386
- .upload ({ file: ' https://www.example.com/public-url.jpg ' , fileName: ' file-name.jpg' })
380
+ .upload ({ file: fs . createReadStream ( ' path/to/file ' ) , fileName: ' file-name.jpg' })
387
381
.asResponse ();
388
382
console .log (response .headers .get (' X-My-Header' ));
389
383
console .log (response .statusText ); // access the underlying Response object
390
384
391
385
const { data : response, response : raw } = await client .files
392
- .upload ({ file: ' https://www.example.com/public-url.jpg ' , fileName: ' file-name.jpg' })
386
+ .upload ({ file: fs . createReadStream ( ' path/to/file ' ) , fileName: ' file-name.jpg' })
393
387
.withResponse ();
394
388
console .log (raw .headers .get (' X-My-Header' ));
395
389
console .log (response .videoCodec );
0 commit comments