A high-performance file gallery built with Cloudflare Workers, Durable Objects, and the DOFS (Durable Objects File System) module. Upload, store, and download files with real-time speed metrics and progress tracking.
- Real-time Upload Progress with live speed calculations and ETA
- Real-time Download Progress with custom modal interface
- Anti-DDoS Protection with smart rate limiting
- Storage Limits (500MB per file, 10GB total)
- Modern UI with drag & drop support
- Speed Metrics for both uploads and downloads
- Edge Storage with global distribution
This project demonstrates file storage using DOFS (Durable Objects File System) instead of the traditional Cloudflare R2. Here's why this approach is interesting:
- DOFS: Files stored directly at the edge, closest to users
- R2: Centralized storage with global CDN distribution
- DOFS: One Durable Object per user/tenant - infinite horizontal scaling
- R2: Single global bucket with shared limits
- DOFS: Perfect tenant isolation (each user gets their own DO)
- R2: Shared storage with application-level permissions
Feature | DOFS (This Project) | Cloudflare R2 |
---|---|---|
Storage Location | Edge nodes worldwide | Regional with CDN |
Latency | Ultra-low (edge storage) | Low (CDN cached) |
Scalability | Per-user Durable Objects | Single global namespace |
Isolation | Perfect (DO per tenant) | Application-level |
File Size Limit | 500MB (configurable) | 5TB per object |
Total Storage | 10GB per DO (unlimited DOs) | Unlimited |
Concurrency | High (distributed DOs) | Very High |
Consistency | Strong (single DO) | Strong |
Setup Complexity | Medium | Low |
Auth Integration | Custom per DO | Global IAM |
Compute:
- Requests: 1M free, then $0.15/million
- Duration: 400K GB-s free, then $12.50/million GB-s
- Memory: 128MB allocated per active DO
Storage (Future):
- Data: 5GB free, then $0.20/GB-month
- Reads: 25B rows free, then $0.001/million rows
- Writes: 50M rows free, then $1.00/million rows
Standard Storage:
- Storage: 10GB free, then $0.015/GB-month
- Class A Ops: 1M free, then $4.50/million
- Class B Ops: 10M free, then $0.36/million
- Egress: Free
Infrequent Access:
- Storage: $0.01/GB-month
- Class A Ops: $9.00/million
- Class B Ops: $0.90/million
- Data Retrieval: $0.01/GB
Scenario | DOFS Cost | R2 Cost | Winner |
---|---|---|---|
Small Scale (1GB, 100K ops) | ~$0 (free tier) | ~$0 (free tier) | π€ Tie |
Medium Scale (100GB, 1M ops) | ~$20/monthΒΉ | ~$6/month | π R2 |
High Traffic (100GB, 10M ops) | ~$25/monthΒΉ | ~$40/month | π DOFS |
Multi-tenant (1000 users) | ~$50/monthΒΉ | ~$60/monthΒ² | π DOFS |
ΒΉ Estimated with future SQLite storage pricing Β² R2 + authentication/isolation overhead
- Multi-tenant applications (SaaS platforms)
- High-performance requirements (gaming, real-time apps)
- Edge-first architecture (global user base)
- Strong isolation needs (compliance, security)
- High request volumes (social media, chat apps)
- Simple file storage (basic websites)
- Large files (video streaming, backups)
- Cost-sensitive projects (personal projects)
- Infrequent access (archives, logs)
- Static websites (images, assets)
- Content distribution (media, downloads)
- Backup storage (databases, files)
- Large file storage (videos, datasets)
- Cost optimization (high storage, low compute)
- Real-time applications (higher latency)
- Multi-tenant isolation (shared namespace)
- Edge computing (centralized storage)
This is a proof of concept that could evolve into:
User Authentication β Multiple DOs per User
βββ DO-User-Files (file storage)
βββ DO-User-Settings (preferences)
βββ DO-User-Analytics (usage stats)
βββ DO-User-Sharing (collaboration)
- Per-user authentication (Auth0, Clerk, etc.)
- Unlimited Durable Objects (one per user/tenant)
- Cross-DO synchronization (shared files)
- Advanced file operations (thumbnails, compression)
- Real-time collaboration (WebSocket support)
- Clone and Deploy
git clone <repo>
cd DOFS-speed
bun install
bun run deploy
- Configure Limits (optional)
// src/durable-object.ts
private uploadSizeLimit = 500 * 1024 * 1024; // 500MB
private totalStorageLimit = 10 * 1024 * 1024 * 1024; // 10GB
- Customize Rate Limits (optional)
// Different limits per operation type
maxRequests = endpoint === 'upload' ? 10 :
endpoint === 'download' ? 30 : 100;
POST /api/upload
- Upload files with progress trackingGET /api/download/{filename}
- Download with speed metricsGET /api/files
- List all uploaded filesGET /api/stats
- Storage usage statisticsDELETE /api/delete/{filename}
- Delete files
- Rate Limiting: 10 uploads, 30 downloads, 100 reads per minute
- File Size Limits: 500MB maximum per file
- Storage Quotas: 10GB total storage per DO
- Input Sanitization: Filename cleaning and validation
- Error Handling: Graceful failure with user feedback
Note: This is a hobby project demonstrating DOFS capabilities. For production use, add authentication, monitoring, and adjust limits based on your needs.
- π File Upload: Drag & drop or click to upload multiple files
- π₯ File Download: Download files with speed metrics
- π Speed Metrics: Real-time upload/download speed measurement
- ποΈ File Management: Delete files you no longer need
- πΎ Storage Stats: View storage usage and available space
- π No Login Required: Simple, open file sharing
- π± Responsive Design: Works on desktop and mobile
- Cloudflare Workers: Serverless runtime
- DOFS: Durable Objects File System for persistent storage
- TypeScript: Type-safe development
- Vanilla JavaScript: No frontend frameworks, just clean HTML/CSS/JS
-
Install dependencies:
bun install
-
Generate Cloudflare types (optional):
bun run cf-typegen
-
Run locally:
bun run dev
-
Deploy to Cloudflare:
bun run deploy
The project is configured with:
- Storage Limit: 10GB (configurable in
src/durable-object.ts
) - Chunk Size: 256KB for optimal performance
- File Storage: Uses DOFS with SQLite backend in Durable Objects
GET /
- Serves the web interfacePOST /api/upload
- Upload files (multipart/form-data)GET /api/files
- List all uploaded filesGET /api/download/{filename}
- Download a specific fileDELETE /api/delete/{filename}
- Delete a specific fileGET /api/stats
- Get storage usage statistics
βββ src/
β βββ index.ts # Main worker entry point
β βββ durable-object.ts # DOFS-powered Durable Object
β βββ types.ts # TypeScript type definitions
βββ package.json # Dependencies and scripts
βββ wrangler.toml # Cloudflare Workers configuration
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
The application measures and displays:
- Server-side timing: Actual time spent writing to DOFS
- File size: Total bytes uploaded
- Upload speed: Bytes per second (server-side)
- Server-side timing: Time to read from DOFS
- Client-side timing: Total download time including network
- Download speed: Calculated from server metrics
- File size: Total bytes downloaded
- Filename sanitization: Prevents path traversal attacks
- File size limits: Enforced by storage quota
- No authentication: Intentionally open for simple file sharing
Edit src/durable-object.ts
and change:
this.fs.setDeviceSize(10 * 1024 * 1024 * 1024); // 10GB
Edit the constructor in src/durable-object.ts
:
this.fs = new Fs(ctx, env, { chunkSize: 256 * 1024 }); // 256KB
The HTML template in src/index.ts
contains all CSS. Modify the styles to customize the appearance.
bun run dev
This starts Wrangler in development mode with hot reloading.
The project uses TypeScript with strict mode enabled. Run type checking with:
tsc --noEmit
bun run deploy
This deploys to your Cloudflare Workers account.
- Single Durable Object: All files are stored in one global Durable Object instance
- No authentication: Anyone can upload/download/delete files
- No file versioning: Uploading a file with the same name overwrites the previous version
- Memory usage: Large files are streamed but still use memory during processing
MIT License - feel free to use this project as a starting point for your own file sharing applications.
This is a simple demonstration project. Feel free to fork and modify for your needs!