writeFile() / write_file() method.
writeFile() / write_file() method.
import fs from 'fs'
import { Volume } from 'e2b'
const volume = await Volume.create('my-volume')
// Read file from local filesystem
const content = fs.readFileSync('/local/path')
// Upload file to volume
await volume.writeFile('/path/in/volume', content)
import fs from 'fs'
import path from 'path'
import { Volume } from 'e2b'
const volume = await Volume.create('my-volume')
const directoryPath = '/local/dir'
const files = fs.readdirSync(directoryPath)
for (const file of files) {
const fullPath = path.join(directoryPath, file)
// Skip directories
if (!fs.statSync(fullPath).isFile()) continue
const content = fs.readFileSync(fullPath)
await volume.writeFile(`/upload/${file}`, content)
}
Was this page helpful?