@@ -48,6 +48,60 @@ const listResponseNode: SFCNodes.ListResponseNode = await client.nodes.list();
4848
4949Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
5050
51+ ## File uploads
52+
53+ Request parameters that correspond to file uploads can be passed in many different forms:
54+
55+ - ` File ` (or an object with the same structure)
56+ - a ` fetch ` ` Response ` (or an object with the same structure)
57+ - an ` fs.ReadStream `
58+ - the return value of our ` toFile ` helper
59+
60+ ``` ts
61+ import fs from ' fs' ;
62+ import SFCNodes , { toFile } from ' @sfcompute/nodes-sdk-alpha' ;
63+
64+ const client = new SFCNodes ();
65+
66+ // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
67+ await client .nodes .create ({
68+ desired_count: 1 ,
69+ max_price_per_node_hour: 1000 ,
70+ zone: ' hayesvalley' ,
71+ cloud_init_user_data: fs .createReadStream (' /path/to/file' ),
72+ });
73+
74+ // Or if you have the web `File` API you can pass a `File` instance:
75+ await client .nodes .create ({
76+ desired_count: 1 ,
77+ max_price_per_node_hour: 1000 ,
78+ zone: ' hayesvalley' ,
79+ cloud_init_user_data: new File ([' my bytes' ], ' file' ),
80+ });
81+
82+ // You can also pass a `fetch` `Response`:
83+ await client .nodes .create ({
84+ desired_count: 1 ,
85+ max_price_per_node_hour: 1000 ,
86+ zone: ' hayesvalley' ,
87+ cloud_init_user_data: await fetch (' https://somesite/file' ),
88+ });
89+
90+ // Finally, if none of the above are convenient, you can use our `toFile` helper:
91+ await client .nodes .create ({
92+ desired_count: 1 ,
93+ max_price_per_node_hour: 1000 ,
94+ zone: ' hayesvalley' ,
95+ cloud_init_user_data: await toFile (Buffer .from (' my bytes' ), ' file' ),
96+ });
97+ await client .nodes .create ({
98+ desired_count: 1 ,
99+ max_price_per_node_hour: 1000 ,
100+ zone: ' hayesvalley' ,
101+ cloud_init_user_data: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ),
102+ });
103+ ```
104+
51105## Handling errors
52106
53107When the library is unable to connect to the API,
0 commit comments