Cloudflare R2
Zero egress fees. S3-compatible.
S3-compatible object storage that eliminates egress bandwidth fees. Perfect for high-traffic applications and content delivery.
How it works
Requests are routed through ObitoX directly to your R2 bucket, leveraging Cloudflare's global network.
โ๏ธSetup
Initialize the ObitoX client with your R2 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 r2 = client.r2({9 accessKey: process.env.R2_ACCESS_KEY,10 secretKey: process.env.R2_SECRET_KEY,11 accountId: process.env.CLOUDFLARE_ACCOUNT_ID,12 bucket: 'my-bucket'13});
Operations
Upload Features
๐คBasic Upload
1const fileUrl = await r2.upload(fileBuffer, {2 filename: 'document.pdf',3 contentType: 'application/pdf'4});5console.log(fileUrl);
๐Progress Tracking
Real-time upload progress
1const url = await r2.upload(stream, {2 filename: 'video.mp4',3 onProgress: (p, uploaded, total) => {4 console.log(`${p}% - ${uploaded}/${total}`);5 }6});
โกSmart Expiry
Network-aware signed URL expiration
Automatically adjusts signed URL expiry based on connection speed to ensure uploads complete even on slow networks.
1const url = await r2.upload(file, {2 filename: 'temp.zip',3 networkInfo: { type: '3g', downlink: 1.5, rtt: 300 }4});
โ File Validation
Magic-byte based validation
1const url = await r2.upload(file, {2 filename: 'img.jpg',3 validation: 'images'4});
Validation presets: 'images' | 'documents'
Batch Upload
๐ฆBatch Upload
Generate presigned URLs for multiple files in one API call.
1const result = await r2.batchUpload({2 files: [3 { buffer: buf1, filename: '1.jpg' },4 { buffer: buf2, filename: '2.jpg' }5 ]6});7console.log(result.summary);
Access Tokens (JWT)
๐Generate Scoped Token
1const { token } = await r2.generateAccessToken({2 bucket: 'my-bucket',3 permissions: ['read', 'write'],4 expiresIn: 36005});
Download URL
๐Signed Download URLs
Generate signed URLs with custom expiration times.
1const { downloadUrl } = await r2.getSignedDownloadUrl({2 fileKey: 'private.pdf',3 expiresIn: 604});
Management
๐List Files
1const { files } = await r2.list({2 prefix: 'photos/',3 limit: 1004});
๐๏ธDelete Files
1await r2.delete({2 fileUrl: 'https://...'3});
๐Auto CORS Configuration
1await r2.configureCors({2 origins: ['https://example.com'],3 allowedMethods: ['GET']4});
Verify CORS
โ Check CORS Configuration
Verify CORS is properly configured on your R2 bucket
1const result = await r2.verifyCors();2if (result.isValid) console.log('CORS OK');
Webhooks
Get notified when uploads complete.
โกAuto Trigger
Server confirms automatically
1const url = await r2.upload(file, {2 webhook: { url: '...', trigger: 'auto' }3});
๐Manual Trigger
You confirm when ready
1const url = await r2.upload(file, {2 webhook: { url: '...', trigger: 'manual' }3});
That's it!
Zero egress, maximum performance.
Upload, serve, and manage files on Cloudflare's global networkโautomatically.
ObitoX handles the complexity for you.