A high-performance, edge-based file storage service implemented with Cloudflare Workers and Rust. The service supports chunked uploads for large files, leveraging Cloudflare's R2 storage and Durable Objects for state management.
- Chunked file upload support for handling large files
- Upload state management using Durable Objects
- Multipart upload capabilities with R2 storage
- Role-based file organization
- CORS support
- Configurable via KV storage
Configuration is managed through Cloudflare KV storage with the following default values:
Config {
durable_object_name: "UPLOAD_TRACKER",
max_file_size: 10_737_418_240, // 10 GB
chunk_size: 157_286_400, // 150 MB
}
POST /v1/uploads/init
Content-Type: application/json
{
"fileName": string,
"totalSize": number,
"userRole": "creator" | "member" | "subscriber",
"contentType": string,
"userId": string
}
POST /v1/uploads/{uploadId}/chunk
Headers:
X-Upload-Id: string
X-Chunk-Index: number
Body: binary
POST /v1/uploads/{uploadId}/complete
Content-Type: application/json
{
"uploadId": string,
"parts": [
{
"etag": string,
"partNumber": number
}
]
}
GET /v1/uploads/{uploadId}
Headers:
X-Upload-Id: string
DELETE /v1/uploads/{uploadId}
Headers:
X-Upload-Id: string
Files are organized in R2 storage using the following path structure:
{userRole}/{userId}/{date}/{contentCategory}/{fileName}
Example:
creator/user123/20240112/image/profile.jpg
The service implements comprehensive error handling for:
- File size limits
- Missing or invalid headers
- Upload state validation
- R2 storage operations
- Invalid user roles
- Rust
- wrangler CLI
- Cloudflare account with Workers, R2, and KV access
- R2 bucket named "BUCKET"
- KV namespace named "CONFIG"
- Durable Object named "UPLOAD_TRACKER"
- Clone the repository
- Configure wrangler.toml with your Cloudflare account details
- Run
wrangler dev
for local development
wrangler publish
- File size limits are enforced
- CORS headers are configured for cross-origin requests
- Role-based file organization
- Unique upload identifiers
This project is licensed under the Apache 2.0 License. For more details, please refer to the LICENSE file.