Writing files to the bucket
Perform Write Operations
This doc covers:
- Uploading files (Buffer + local paths)
- Changing bucket visibility
- Generating pre-signed URLs
All requests are authenticated using X-Token.
Upload a Buffer
import { getInstance } from 'nvsfsdk';
const ns = getInstance();
const data = Buffer.from('hello world');
await ns.uploadBuffer('hello.txt', data, 'text/plain');
Upload a local file path
Uploads a file from disk.
import { getInstance } from 'nvsfsdk';
const ns = getInstance();
await ns.uploadFile('uploads/', './local/path/to/file.png');
- If the
keyends with/, the SDK appends the file name automatically. - Small files are uploaded with the JSON base64 endpoint.
- Large files are uploaded using the multipart/WebSocket path.
Upload progress
await ns.uploadFile('uploads/', './big.iso', {
progress: (p) => console.log(`upload: ${p}%`),
});
Make a bucket public/private
await ns.setBucketPublic(true);
await ns.setBucketPublic(false);
Pre-signed URLs
Pre-signed URLs let you grant temporary access without exposing your token. The bucket name is automatically derived from your token.
const signed = await ns.presignUrl('uploads/file.png', {
ttl: 60 * 15,
method: 'GET',
});
console.log(signed.signedUrl);
PUT pre-signed URL
const signedPut = await ns.presignUrl('uploads/new.bin', {
ttl: 60 * 10,
method: 'PUT',
});
Reroll token
Rotates your token (invalidates the old one).
const rotated = await ns.rerollToken();
console.log(rotated.bucket_token);
Was this page helpful?
Last updated 2 weeks ago
Built with Documentation.AI