ObitoX Docs
Providers
Storage ProviderHIGH PERFORMANCE

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.

Your App
Client
Uploads File
Authentication
ObitoX
Gateway
Stores Object
R2
Global Store
Global CDN
S3 Compatible
Zero Egress

โš™๏ธSetup

Initialize the ObitoX client with your R2 credentials

typescript
1import ObitoX from '@obitox/upload';
2
3const client = new ObitoX({
4 apiKey: process.env.OBITOX_API_KEY,
5 apiSecret: process.env.OBITOX_API_SECRET
6});
7
8const 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});

Upload Features

๐Ÿ“คBasic Upload

typescript
1const fileUrl = await r2.upload(fileBuffer, {
2 filename: 'document.pdf',
3 contentType: 'application/pdf'
4});
5console.log(fileUrl);

๐Ÿ“ŠProgress Tracking

Real-time upload progress

typescript
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.

typescript
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

typescript
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.

typescript
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

typescript
1const { token } = await r2.generateAccessToken({
2 bucket: 'my-bucket',
3 permissions: ['read', 'write'],
4 expiresIn: 3600
5});

Download URL

๐Ÿ”—Signed Download URLs

Generate signed URLs with custom expiration times.

typescript
1const { downloadUrl } = await r2.getSignedDownloadUrl({
2 fileKey: 'private.pdf',
3 expiresIn: 60
4});

Management

๐Ÿ“‹List Files

typescript
1const { files } = await r2.list({
2 prefix: 'photos/',
3 limit: 100
4});

๐Ÿ—‘๏ธDelete Files

typescript
1await r2.delete({
2 fileUrl: 'https://...'
3});

๐ŸŒAuto CORS Configuration

typescript
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

typescript
1const result = await r2.verifyCors();
2if (result.isValid) console.log('CORS OK');

Webhooks

Get notified when uploads complete.

โšกAuto Trigger

Server confirms automatically

typescript
1const url = await r2.upload(file, {
2 webhook: { url: '...', trigger: 'auto' }
3});

๐Ÿ‘†Manual Trigger

You confirm when ready

typescript
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.

On this page