Documentation Index
Fetch the complete documentation index at: https://docs.ondb.ai/llms.txt
Use this file to discover all available pages before exploring further.
OnDB supports uploading and retrieving binary files like images, videos, and documents.
Upload Blob
// Browser upload with File object
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const uploadResult = await client.uploadBlob(
{
collection: 'avatars',
blob: file,
metadata: {
user_address: '0xabc...',
uploaded_by: 'alice',
is_primary: true
}
},
// Optional payment callback (if collection requires payment)
async (quote) => {
const txHash = await processPayment(quote);
return { txHash, network: quote.network, sender: walletAddress, chainType: quote.chainType, paymentMethod: 'native' };
}
);
console.log('Blob ID:', uploadResult.blob_id);
// Wait for upload completion
const task = await client.waitForTaskCompletion(uploadResult.ticket_id);
Retrieve Blob
// Browser: Display image
const blob = await client.retrieveBlob({
collection: 'avatars',
blob_id: 'blob_abc123'
});
const imageUrl = URL.createObjectURL(blob);
document.querySelector('img').src = imageUrl;
// Node.js: Save file
const buffer = await client.retrieveBlob({
collection: 'documents',
blob_id: 'blob_xyz789'
});
fs.writeFileSync('./downloaded-file.pdf', buffer);
Complete Example: Avatar Upload
async function uploadAvatar(file: File, userAddress: string) {
// Upload blob with payment callback
const uploadResult = await client.uploadBlob(
{
collection: 'avatars',
blob: file,
metadata: {
user_address: userAddress,
is_primary: true,
uploaded_at: new Date().toISOString()
}
},
async (quote) => {
console.log(`Upload will cost ${quote.totalCost} ${quote.tokenSymbol}`);
const txHash = await processPayment(quote);
return { txHash, network: quote.network, sender: userAddress, chainType: quote.chainType, paymentMethod: 'native' };
}
);
// Wait for confirmation
await client.waitForTaskCompletion(uploadResult.ticket_id);
return uploadResult.blob_id;
}
Supported File Types
OnDB blob storage supports any binary file type including:
- Images (PNG, JPG, GIF, WebP, SVG)
- Videos (MP4, WebM)
- Documents (PDF, DOCX)
- Audio (MP3, WAV)
- Archives (ZIP, TAR)
Size Limits
Maximum blob size is 2MB per file. For larger files, consider:
- Compressing images before upload
- Splitting large files into chunks
- Using external storage with OnDB for metadata
Next Steps
Batch Operations
Bulk data operations
Task Management
Async operations tracking