Skip to content

Commit 884d2df

Browse files
feat(api): manual updates
1 parent fb49dce commit 884d2df

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
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: 18 additions & 12 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: fs.createReadStream('path/to/file'),
34+
file: 'https://www.example.com/public-url.jpg',
3535
fileName: 'file-name.jpg',
3636
});
3737

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

5454
const params: ImageKit.FileUploadParams = {
55-
file: fs.createReadStream('path/to/file'),
55+
file: 'https://www.example.com/public-url.jpg',
5656
fileName: 'file-name.jpg',
5757
};
5858
const response: ImageKit.FileUploadResponse = await client.files.upload(params);
@@ -76,17 +76,23 @@ 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.files.upload({ file: fs.createReadStream('/path/to/file'), fileName: 'fileName' });
79+
await client.beta.v2.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.files.upload({ file: new File(['my bytes'], 'file'), fileName: 'fileName' });
82+
await client.beta.v2.files.upload({ file: new File(['my bytes'], 'file'), fileName: 'fileName' });
8383

8484
// You can also pass a `fetch` `Response`:
85-
await client.files.upload({ file: await fetch('https://somesite/file'), fileName: 'fileName' });
85+
await client.beta.v2.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.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' });
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+
});
9096
```
9197

9298
## Handling errors
@@ -98,7 +104,7 @@ a subclass of `APIError` will be thrown:
98104
<!-- prettier-ignore -->
99105
```ts
100106
const response = await client.files
101-
.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' })
107+
.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' })
102108
.catch(async (err) => {
103109
if (err instanceof ImageKit.APIError) {
104110
console.log(err.status); // 400
@@ -139,7 +145,7 @@ const client = new ImageKit({
139145
});
140146

141147
// Or, configure per-request:
142-
await client.files.upload({ file: fs.createReadStream('path/to/file'), fileName: 'file-name.jpg' }, {
148+
await client.files.upload({ file: 'https://www.example.com/public-url.jpg', fileName: 'file-name.jpg' }, {
143149
maxRetries: 5,
144150
});
145151
```
@@ -156,7 +162,7 @@ const client = new ImageKit({
156162
});
157163

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

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

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

src/resources/files/files.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
Versions,
2626
} from './versions';
2727
import { APIPromise } from '../../core/api-promise';
28-
import { type Uploadable } from '../../core/uploads';
2928
import { buildHeaders } from '../../internal/headers';
3029
import { RequestOptions } from '../../internal/request-options';
3130
import { multipartFormRequestOptions } from '../../internal/uploads';
@@ -175,7 +174,7 @@ export class Files extends APIResource {
175174
* @example
176175
* ```ts
177176
* const response = await client.files.upload({
178-
* file: fs.createReadStream('path/to/file'),
177+
* file: 'https://www.example.com/path/to-image.jpg',
179178
* fileName: 'fileName',
180179
* });
181180
* ```
@@ -1079,7 +1078,7 @@ export interface FileUploadParams {
10791078
* When supplying a URL, the server must receive the response headers within 8
10801079
* seconds; otherwise the request fails with 400 Bad Request.
10811080
*/
1082-
file: Uploadable;
1081+
file: string;
10831082

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

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

Lines changed: 3 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, { toFile } from '@imagekit/nodejs';
3+
import ImageKit from '@imagekit/nodejs';
44

55
const client = new ImageKit({
66
privateAPIKey: 'My Private API Key',
@@ -154,7 +154,7 @@ describe('resource files', () => {
154154
// Prism tests are disabled
155155
test.skip('upload: only required params', async () => {
156156
const responsePromise = client.files.upload({
157-
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
157+
file: 'https://www.example.com/path/to-image.jpg',
158158
fileName: 'fileName',
159159
});
160160
const rawResponse = await responsePromise.asResponse();
@@ -169,7 +169,7 @@ describe('resource files', () => {
169169
// Prism tests are disabled
170170
test.skip('upload: required and optional params', async () => {
171171
const response = await client.files.upload({
172-
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
172+
file: 'https://www.example.com/path/to-image.jpg',
173173
fileName: 'fileName',
174174
token: 'token',
175175
checks: '"request.folder" : "marketing/"\n',

0 commit comments

Comments
 (0)