S3
Industry standard object storage.
Works with AWS S3 and any S3-compatible storage (MinIO, DigitalOcean Spaces, Wasabi, etc).
How it works
Unified API for all S3 providers. Switch providers just by changing credentials.
⚙️Setup
Initialize the ObitoX client with your S3 credentials
1import ObitoX from '@obitox/upload';23const client = new ObitoX({4 apiKey: process.env.OBITOX_API_KEY,5 apiSecret: process.env.OBITOX_API_SECRET6});78const s3 = client.s3({9 accessKey: process.env.S3_ACCESS_KEY,10 secretKey: process.env.S3_SECRET_KEY,11 bucket: 'my-bucket',12 region: 'us-east-1'13});
Operations
Setup Options
🔌Custom Endpoint (S3 Compatible)
Works with MinIO, DigitalOcean Spaces, or any generic S3 API.
1const s3 = client.s3({2 accessKey: 'minioadmin',3 secretKey: 'minioadmin123',4 bucket: 'local-bucket',5 endpoint: 'http://localhost:9000',6 region: 'us-east-1'7});
⚡Direct API
Alternative setup: pass credentials per-call (Direct API)
1const fileUrl = await client.uploadFile(file, {2 provider: 'S3',3 s3AccessKey: 'key',4 s3SecretKey: 'secret',5 s3Bucket: 'bucket',6 s3Region: 'us-east-1'7});
Upload Features
📤Basic Upload
1const url = await s3.upload(file, {2 filename: 'document.txt'3});
Note: Smart Expiry/Network-Aware uploads are enabled by default for browser uploads. See Smart Expiry below.
📊Progress Tracking
Monitor upload progress
1const url = await s3.upload(file, {2 filename: 'video.mp4',3 onProgress: (percent, uploaded, total) => {4 console.log(`${percent}% — ${uploaded}/${total} bytes`);5 }6});
⏳Signed URL Expiry
Set custom expiry for returned URLs
1const url = await s3.upload(file, {2 filename: 'doc.txt',3 expiresIn: 36004});
📡Smart Expiry (Network-Aware)
SDK automatically detects network conditions in the browser to set optimal URL expiry.
navigator.connection to optimize timeouts.1// 1. Auto-Detect (Default in Browser)2// SDK automatically uses navigator.connection3const url = await s3.upload(file, {4 filename: 'video.mp4'5});67// 2. Manual Override (Server-side or custom)8const url = await s3.upload(file, {9 filename: 'video.mp4',10 networkInfo: {11 type: '4g',12 downlink: 10, // Mbps13 rtt: 50 // ms14 }15});
🕵️Magic Bytes Validation
Validate file content matches extension
1const url = await s3.upload(file, {2 filename: 'photo.jpg',3 validation: 'images'4});
Validation presets: 'images' | 'documents'
Multipart Upload
📦Automatic Multipart
Large files (>100MB by default) are automatically split and uploaded in parts.
1// Automatic for large files2const url = await s3.upload(largeFile, {3 filename: 'archive.zip',4 onProgress: (p) => console.log(p)5});
Batch Upload
📚Batch Upload
Generate presigned URLs for multiple files in one API call.
1const result = await s3.batchUpload({2 files: [3 { filename: 'a.txt', contentType: 'text/plain', fileSize: 100 },4 { filename: 'b.jpg', contentType: 'image/jpeg', fileSize: 500 }5 ]6});7console.log(result.summary);
Download URL
🔗Signed Download URLs
1const url = await s3.getSignedDownloadUrl({2 fileKey: 'doc.txt',3 expiresIn: 36004});
Management
📋List Files
1const res = await s3.list({ maxKeys: 100 });2res.files.forEach(f => console.log(f.key));
🗑️Delete Files
1await s3.delete({ fileKey: 'doc.txt' });
Auto CORS Configuration
🌐Configure CORS
Set CORS rules on your S3 bucket
1await s3.configureCors({2 origins: ['https://example.com'],3 allowedMethods: ['GET', 'POST']4});
File Metadata
📄Get File Metadata
Get file metadata without downloading
1const meta = await s3.getMetadata({ key: 'doc.txt' });
Webhooks
Notification system for upload completion.
⚡Auto Trigger
Server confirms automatically
1const url = await s3.upload(file, {2 filename: 'report.pdf',3 webhook: {4 url: 'https://api.myapp.com/hooks',5 trigger: 'auto'6 }7});
👆Manual Trigger
You confirm when ready
1const url = await s3.upload(file, {2 filename: 'invoice.pdf',3 webhook: {4 url: 'https://api.myapp.com/hooks',5 trigger: 'manual',6 secret: 'secret-key'7 }8});
🔐Signature Verification
Verify webhook authenticity on your server
1import crypto from 'crypto';23function verify(payload, signature, secret) {4 const hmac = crypto.createHmac('sha256', secret);5 hmac.update(JSON.stringify(payload));6 return signature === `sha256=${hmac.digest('hex')}`;7}
That's it!
Any S3 provider, one unified SDK.
Upload securely, handle large files automatically, and switch providers instantly.
ObitoX handles the complexity for you.