Skip to content

Commit 8e74b46

Browse files
committed
Update README with Storage info
1 parent 93bca5a commit 8e74b46

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ const api = new YepCodeApi({ apiToken: '****' });
104104
const processes = await api.getProcesses();
105105
```
106106

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+
107132
## SDK API Reference
108133

109134
### YepCodeRun
@@ -291,6 +316,55 @@ interface Process {
291316
}
292317
```
293318

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+
294368
## License
295369

296370
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)