Skip to content

Commit 316a6af

Browse files
chore(internal): codegen related update (#138)
1 parent 7e3ba08 commit 316a6af

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ main();
5757

5858
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
5959

60+
## File uploads
61+
62+
Request parameters that correspond to file uploads can be passed in many different forms:
63+
64+
- `File` (or an object with the same structure)
65+
- a `fetch` `Response` (or an object with the same structure)
66+
- an `fs.ReadStream`
67+
- the return value of our `toFile` helper
68+
69+
```ts
70+
import fs from 'fs';
71+
import fetch from 'node-fetch';
72+
import Browserbase, { toFile } from '@browserbasehq/sdk';
73+
74+
const client = new Browserbase();
75+
76+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
77+
await client.extensions.create({ file: fs.createReadStream('/path/to/file') });
78+
79+
// Or if you have the web `File` API you can pass a `File` instance:
80+
await client.extensions.create({ file: new File(['my bytes'], 'file') });
81+
82+
// You can also pass a `fetch` `Response`:
83+
await client.extensions.create({ file: await fetch('https://somesite/file') });
84+
85+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
86+
await client.extensions.create({ file: await toFile(Buffer.from('my bytes'), 'file') });
87+
await client.extensions.create({ file: await toFile(new Uint8Array([0, 1, 2]), 'file') });
88+
```
89+
6090
## Handling errors
6191

6292
When the library is unable to connect to the API,

0 commit comments

Comments
 (0)