The R2 File Manager is for use on Cloudflare Workers. It provides an intuitive interface for managing files on Cloudflare R2 Storage. It can be protected by employing Cloudflare Access.
The system includes the following features:
- File Upload: Users can upload files to the server. This is done via a
PUTrequest to the server. The file data is stored in the R2 bucket under the given key. - File Listing: Users can view a list of uploaded files. This is achieved by maintaining a
file-list.txtin the bucket that contains the names of all uploaded files. The list is updated whenever a file is uploaded or deleted. - File Download: Users can download any uploaded file. This is done via a
GETrequest with the file's key. The file data is fetched from the R2 bucket. - File Deletion: Users can delete any uploaded file. This is done via a
GETrequest to the/delete/{filename}path. The file is removed from the R2 bucket and the file name is removed fromfile-list.txt.
The system is designed to be run by Cloudflare Workers.
The worker handles the following HTTP methods:
GET: Fetches the file list or a specific file, or handles file deletion.PUT: Uploads a file to the server.POST: Receives file data from a form and saves the file.
Install the required packages and follow the Cloudflare tutorials.
npm create cloudflare@latestcdto the new application directorywrangler r2 bucket create <YOUR_BUCKET_NAME>mv wrangler.toml wrangler.toml.bak && echo -e "name = 'YOUR_APPLICATION_NAME'\nmain = 'src/worker.ts'\ncompatibility_date = 'yyyy-mm-dd'\n\n[[r2_buckets]]\nbinding = 'MY_BUCKET'\nbucket_name = '<YOUR_BUCKET_NAME>'" > wrangler.tomlmv src/worker.ts src/worker.ts.bakwget -P src https://raw.githubusercontent.com/msaifuddin/r2-file-manager/main/worker.tsnpx wrangler deploy
Please keep an eye on your R2 charges (Cloudflare R2 Pricing). The functions implemented in this system will generate a number of Class A & B requests. If you want to keep your usage within the free tier, make sure to monitor your usage.
There is no authentication implemented in this system, as I'm using Cloudflare Access as the access control method. You should add your custom domain and/or the worker domain <worker>.<name>.workers.dev to be protected by Access (Self-hosted).
This project is licensed under the MIT license.


