import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create({ secure: true })
const filePathInSandbox = '/tmp/test-file'
// Generate pre signature upload URL
const publicUploadUrl = await sandbox.uploadUrl(filePathInSandbox, {
useSignatureExpiration: 120, // optional
})
// Simulate browser behavior
const form = new FormData()
form.append('file', new Blob(['file content']), 'test-file')
const uploadRes = await fetch(publicUploadUrl, {
method: 'POST',
body: form,
})
if (!uploadRes.ok) {
throw new Error(`Upload failed: ${uploadRes.status} ${await uploadRes.text()}`)
}
// SDK Read Back Verification
const result = await sandbox.files.read(filePathInSandbox)
console.log(result)
await sandbox.kill()