@rivium/storage-node
v0.1.0
Published
RiviumStorage Node.js SDK - File storage and image transformation service
Maintainers
Readme
Installation
npm install @rivium-storage/nodeQuick Start
Client Mode (apiKey only)
import { RiviumStorage } from '@rivium-storage/node';
const storage = new RiviumStorage({
apiKey: 'rv_live_xxx',
userId: 'user-123', // optional, for policy enforcement
});
// Upload a file
const file = await storage.upload('my-bucket-id', 'images/photo.jpg', imageBuffer, {
contentType: 'image/jpeg',
});
// Download
const data = await storage.download(file.id);
// Transform URL
const url = storage.getTransformUrl(file.id, { width: 200, format: 'webp' });Server Mode (apiKey + serverSecret)
const admin = new RiviumStorage({
apiKey: 'rv_live_xxx',
serverSecret: 'rv_srv_xxx', // bypasses all bucket policies
});
// Create bucket
const bucket = await admin.createBucket('user-uploads', {
visibility: 'private',
maxFileSize: 10 * 1024 * 1024,
});
// Generate signed upload URL for client-side uploads
const { url } = await admin.createSignedUploadUrl(bucket.id, 'uploads/photo.jpg', {
contentType: 'image/jpeg',
expiresIn: 300,
});
// Apply policy template
await admin.applyPolicyTemplate(bucket.id, 'publicRead');
// Delete files (requires serverSecret)
await admin.deleteMany(['file-id-1', 'file-id-2']);Features
- File Upload & Download — Upload from Buffer, Uint8Array, or string
- Bucket Management — Create, list, get, delete buckets
- URL Generation — Public, download, and transform URLs
- Image Transformations — Resize, crop, format conversion, blur, sharpen, rotate
- Signed URLs — Secure time-limited upload and download URLs
- Bucket Policies — Firebase-like access rules with templates (publicRead, private, userFolders, imagesOnly, closed)
- Dual Mode — Client mode (apiKey) and server mode (apiKey + serverSecret)
- Policy Enforcement — User-scoped access control via
userId - TypeScript First — Full type definitions included
Documentation
For full documentation, visit rivium.co/docs.
License
MIT License — see LICENSE for details.
