@@ -104,6 +104,31 @@ const api = new YepCodeApi({ apiToken: '****' });
104
104
const processes = await api .getProcesses ();
105
105
```
106
106
107
+ ### 6. Storage Objects
108
+
109
+ You can manage files in your YepCode workspace using the ` YepCodeStorage ` class. This allows you to upload, list, download, and delete files easily.
110
+
111
+ ``` js
112
+ const { YepCodeStorage } = require (' @yepcode/run' );
113
+ const fs = require (' fs' );
114
+
115
+ const storage = new YepCodeStorage ({ apiToken: ' ****' });
116
+
117
+ // Upload a file (using Node.js stream)
118
+ await storage .upload (' path/myfile.txt' , fs .createReadStream (' ./myfile.txt' ));
119
+
120
+ // List files
121
+ const files = await storage .list ();
122
+ console .log (files);
123
+
124
+ // Download a file
125
+ const stream = await storage .download (' path/myfile.txt' );
126
+ stream .pipe (fs .createWriteStream (' ./downloaded.txt' ));
127
+
128
+ // Delete a file
129
+ await storage .delete (' myfile.txt' );
130
+ ```
131
+
107
132
## SDK API Reference
108
133
109
134
### YepCodeRun
@@ -291,6 +316,55 @@ interface Process {
291
316
}
292
317
```
293
318
319
+ ### YepCodeStorage
320
+
321
+ Manages file storage in your YepCode workspace. Allows you to upload, list, download, and delete files using the YepCode API.
322
+
323
+ #### Constructor
324
+
325
+ ``` typescript
326
+ constructor (options ?: {
327
+ apiToken?: string ; // Optional if YEPCODE_API_TOKEN env var is set
328
+ })
329
+ ```
330
+
331
+ #### Methods
332
+
333
+ ##### ` upload(filename: string, file: File | Blob | Readable): Promise<StorageObject> `
334
+ Uploads a file to YepCode storage.
335
+
336
+ - ` filename ` : Name to assign to the uploaded file
337
+ - ` file ` : The file to upload (can be a File, Blob, or Node.js Readable stream)
338
+ - ** Returns:** Promise<StorageObject >
339
+
340
+ ##### ` list(): Promise<StorageObject[]> `
341
+ Lists all files in YepCode storage.
342
+
343
+ - ** Returns:** Promise<StorageObject[ ] >
344
+
345
+ ##### ` download(filename: string): Promise<Readable> `
346
+ Downloads a file from YepCode storage as a Node.js Readable stream.
347
+
348
+ - ` filename ` : Name of the file to download
349
+ - ** Returns:** Promise<Readable >
350
+
351
+ ##### ` delete(filename: string): Promise<void> `
352
+ Deletes a file from YepCode storage.
353
+
354
+ - ` filename ` : Name of the file to delete
355
+ - ** Returns:** Promise<void >
356
+
357
+ ##### ` StorageObject `
358
+ ``` typescript
359
+ interface StorageObject {
360
+ name: string ;
361
+ url: string ;
362
+ size? : number ;
363
+ contentType? : string ;
364
+ createdAt? : string ;
365
+ }
366
+ ```
367
+
294
368
## License
295
369
296
370
This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
0 commit comments