@@ -57,6 +57,36 @@ main();
57
57
58
58
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
59
59
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
+
60
90
## Handling errors
61
91
62
92
When the library is unable to connect to the API,
0 commit comments