Skip to main content
Version: 0.1.0

Uploads

Upload files and generate signed asset URLs.

Single File Upload

From the client

const upload = await client.upload(file, {
repository: 'myapp',
workspace: 'content',
path: '/images/photo.jpg',
onProgress: (progress) => {
console.log(`${Math.round(progress.progress * 100)}%`);
},
});

From a workspace

const ws = db.workspace('content');
const upload = await ws.upload(file, '/images/photo.jpg');

Node.js file path

const upload = await client.uploadFile('/local/path/to/file.pdf', {
repository: 'myapp',
workspace: 'content',
path: '/docs/report.pdf',
});

Batch Upload

Upload multiple files with concurrency control and progress tracking.

const batch = await client.uploadFiles(files, {
repository: 'myapp',
workspace: 'content',
basePath: '/images/',
concurrency: 3,
onProgress: (progress) => {
console.log(
`${progress.filesCompleted}/${progress.filesTotal} files, ` +
`${Math.round(progress.progress * 100)}%`
);
},
onFileComplete: (file) => {
console.log('Completed:', file);
},
onFileError: (file, error) => {
console.error('Failed:', file, error);
},
});

Workspace shorthand:

const ws = db.workspace('content');
const batch = await ws.uploadFiles(fileList, '/images/');

Upload Management

Get active upload

const upload = client.getUpload(uploadId);

List all active uploads

const uploads = client.getActiveUploads();

Cancel all uploads

await client.cancelAllUploads();

Signed Asset URLs

Generate time-limited URLs for accessing binary assets stored in RaisinDB.

const { url } = await client.signAssetUrl({
repository: 'myapp',
workspace: 'content',
path: '/images/photo.jpg',
});

Workspace shorthand:

const ws = db.workspace('content');
const { url } = await ws.signAssetUrl('/images/photo.jpg');

Types

UploadOptions

interface UploadOptions {
repository: string;
workspace: string;
path: string;
branch?: string;
nodeType?: string;
onProgress?: (progress: UploadProgress) => void;
onComplete?: () => void;
onError?: (error: Error) => void;
}

BatchUploadOptions

interface BatchUploadOptions {
repository: string;
workspace: string;
basePath: string;
branch?: string;
concurrency?: number;
onProgress?: (progress: BatchProgress) => void;
onFileComplete?: (file: string) => void;
onFileError?: (file: string, error: Error) => void;
}

UploadProgress

interface UploadProgress {
uploadId: string;
loaded: number;
total: number;
progress: number; // 0..1
}

BatchProgress

interface BatchProgress {
filesCompleted: number;
filesTotal: number;
loaded: number;
total: number;
progress: number; // 0..1
}