Skip to content

Commit 96750df

Browse files
feat(api): manual updates
1 parent df0ccf7 commit 96750df

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
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: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const client = new ImageKit({
3131
});
3232

3333
const response = await client.files.upload({
34-
file: 'https://www.example.com/public-url.jpg',
34+
file: fs.createReadStream('path/to/file'),
3535
fileName: 'file-name.jpg',
3636
});
3737

@@ -52,7 +52,7 @@ const client = new ImageKit({
5252
});
5353

5454
const params: ImageKit.FileUploadParams = {
55-
file: 'https://www.example.com/public-url.jpg',
55+
file: fs.createReadStream('path/to/file'),
5656
fileName: 'file-name.jpg',
5757
};
5858
const response: ImageKit.FileUploadResponse = await client.files.upload(params);
@@ -76,23 +76,17 @@ import ImageKit, { toFile } from '@imagekit/nodejs';
7676
const client = new ImageKit();
7777

7878
// 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' });
8080

8181
// 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' });
8383

8484
// 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' });
8686

8787
// 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' });
9690
```
9791

9892
## Handling errors
@@ -104,7 +98,7 @@ a subclass of `APIError` will be thrown:
10498
<!-- prettier-ignore -->
10599
```ts
106100
const response = await client.files
107-
.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' })
101+
.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' })
108102
.catch(async (err) => {
109103
if (err instanceof ImageKit.APIError) {
110104
console.log(err.status); // 400
@@ -145,7 +139,7 @@ const client = new ImageKit({
145139
});
146140

147141
// Or, configure per-request:
148-
await client.files.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' }, {
142+
await client.files.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' }, {
149143
maxRetries: 5,
150144
});
151145
```
@@ -162,7 +156,7 @@ const client = new ImageKit({
162156
});
163157

164158
// Override per-request:
165-
await client.files.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' }, {
159+
await client.files.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' }, {
166160
timeout: 5 * 1000,
167161
});
168162
```
@@ -186,13 +180,13 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
186180
const client = new ImageKit();
187181

188182
const response = await client.files
189-
.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' })
183+
.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' })
190184
.asResponse();
191185
console.log(response.headers.get('X-My-Header'));
192186
console.log(response.statusText); // access the underlying Response object
193187

194188
const { data: response, response: raw } = await client.files
195-
.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' })
189+
.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' })
196190
.withResponse();
197191
console.log(raw.headers.get('X-My-Header'));
198192
console.log(response.videoCodec);

src/resources/files/files.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Versions,
2626
} from './versions';
2727
import { APIPromise } from '../../core/api-promise';
28+
import { type Uploadable } from '../../core/uploads';
2829
import { buildHeaders } from '../../internal/headers';
2930
import { RequestOptions } from '../../internal/request-options';
3031
import { multipartFormRequestOptions } from '../../internal/uploads';
@@ -174,7 +175,7 @@ export class Files extends APIResource {
174175
* @example
175176
* ```ts
176177
* const response = await client.files.upload({
177-
* file: 'file',
178+
* file: fs.createReadStream('path/to/file'),
178179
* fileName: 'fileName',
179180
* });
180181
* ```
@@ -1078,7 +1079,7 @@ export interface FileUploadParams {
10781079
* When supplying a URL, the server must receive the response headers within 8
10791080
* seconds; otherwise the request fails with 400 Bad Request.
10801081
*/
1081-
file: string;
1082+
file: Uploadable;
10821083

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

tests/api-resources/files/files.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import ImageKit from '@imagekit/nodejs';
3+
import ImageKit, { toFile } from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateAPIKey: 'My Private API Key',
@@ -153,7 +153,10 @@ describe('resource files', () => {
153153

154154
// Prism tests are disabled
155155
test.skip('upload: only required params', async () => {
156-
const responsePromise = client.files.upload({ file: 'file', fileName: 'fileName' });
156+
const responsePromise = client.files.upload({
157+
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
158+
fileName: 'fileName',
159+
});
157160
const rawResponse = await responsePromise.asResponse();
158161
expect(rawResponse).toBeInstanceOf(Response);
159162
const response = await responsePromise;
@@ -166,7 +169,7 @@ describe('resource files', () => {
166169
// Prism tests are disabled
167170
test.skip('upload: required and optional params', async () => {
168171
const response = await client.files.upload({
169-
file: 'file',
172+
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
170173
fileName: 'fileName',
171174
token: 'token',
172175
checks: '"request.folder" : "marketing/"\n',

0 commit comments

Comments
 (0)