cloudflare-r2-file-manager is a full-stack web application for managing files and folders stored in Cloudflare R2. It provides both a modern web interface and REST API for performing CRUD operations on files and folders within your R2 bucket.
- Modern UI: Clean, responsive web interface built with HTML5, Tailwind CSS, and Alpine.js
- File Browser: Navigate folders with breadcrumb navigation
- Multi-Select: Advanced file selection with Shift+Click range selection, Ctrl+A, and Esc to clear
- Drag & Drop: Intuitive file and folder upload interface
- Real-time Feedback: Toast notifications and progress indicators
- Create JSON files and folders
- Read and update file contents
- Delete single files or multiple files in batch
- Upload multiple files (up to 50 per request) with progress tracking
- Folder Upload: Upload entire directory structures while preserving hierarchy
- Batch Operations: Delete multiple files in a single request
- Natural Sorting: Proper alphanumeric sorting for files and folders
- Keyboard Shortcuts: Full keyboard navigation support
- Responsive Design: Mobile-friendly interface
- Progress Tracking: Real-time upload progress with visual indicators
- Error Handling: Comprehensive error handling with user-friendly messages
- RESTful API for all file operations
- Pre-signed URL generation for secure file access
- Batch operations for improved performance
- CORS support for web applications
- Node.js (v14 or above)
- Cloudflare R2 account and API credentials
-
Clone the repository:
https://github.com/YsrajSingh/cloudflare-r2-file-manager.git cd cloudflare-r2-file-manager -
Install dependencies:
npm install
-
Create an .env file in the root directory with the following content:
PORT=3000 AWS_ACCESS_KEY_ID=<your-cloudflare-r2-access-key> AWS_SECRET_ACCESS_KEY=<your-cloudflare-r2-secret-key> R2_BUCKET_NAME=<your-cloudflare-r2-bucket-name> R2_BUCKET=<your-cloudflare-r2-bucket-name> R2_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
Replace
<your-cloudflare-r2-access-key>,<your-cloudflare-r2-secret-key>,<your-cloudflare-r2-bucket-name>, and<account-id>with your Cloudflare R2 credentials.
To start the server, run:
npm startThe server will be available at http://localhost:3000
Once the server is running, visit http://localhost:3000 in your browser to access the web interface:
- File Browser: Navigate through your folders with breadcrumb navigation
- Multi-Select: Select multiple files with Shift+Click range selection, Ctrl+A, or individual clicks
- File Operations: Create, upload, delete, and manage files and folders
- Folder Upload: Upload entire directory structures while preserving hierarchy
- Batch Operations: Delete multiple files efficiently in single requests
- Progress Tracking: Real-time upload progress with visual indicators
- Responsive Design: Works on desktop and mobile devices
- Keyboard Shortcuts: Full keyboard navigation support
- Navigation: Click on folders to navigate, use breadcrumbs to go back
- File Selection: Click files to select, Shift+Click for ranges, Ctrl+A for all
- Upload: Use "Upload" button to select files or drag & drop folders
- Delete: Select files and click "Delete" for batch deletion
- Create: Use "New Folder" or "New File" buttons to create content
- Create a File
-
Endpoint:
POST /create-file -
Request Body:
{ "folder": "folder-name", "fileName": "file.json", "content": { "key": "value" } }
- Delete a File
-
Endpoint:
DELETE /delete-file -
Request Body (single file):
{ "folder": "folder-name", "fileName": "file.json" } -
Request Body (batch delete multiple files):
{ "folder": "folder-name", "fileNames": ["file1.json", "file2.json", "file3.json"] } -
Request Body (delete all files in folder):
{ "folder": "folder-name", "fileName": "*" } -
Response:
{"message": "Deleted X files successfully"}or{"message": "Deleted X files successfully, Y files failed", "deleted": X, "failed": Y, "errors": [...]}
- Update a File
-
Endpoint:
PUT /update-file -
Request Body:
{ "folder": "folder-name", "fileName": "file.json", "content": { "key": "updated-value" } }
- Read a File
- Endpoint:
GET /read-file - Query Parameters:
folder=folder-name&fileName=file.json
- List Files in a Folder
- Endpoint:
GET /list-files - Query Parameters:
folder=folder-name
- List All Folders
- Endpoint:
GET /list-folders
- Duplicate a Folder
-
Endpoint:
POST /duplicate-folder -
Request Body:
{ "sourceFolder": "source-folder", "targetFolder": "target-folder" }
- Rename a Folder
-
Endpoint:
PUT /rename-folder -
Request Body:
{ "sourceFolder": "old-folder-name", "targetFolder": "new-folder-name" }
- Upload Files
- Endpoint:
POST /upload-files - Content-Type:
multipart/form-data - Form Data:
files: Multiple files (up to 50 per request, processed in batches of 10)folder: Target folder name (optional, defaults to "uploads")
- Response:
{"message": "Files uploaded successfully", "fileNames": ["file1.jpg", "file2.png"]}
- Get File URLs
- Endpoint:
GET /get-file-urls - Query Parameters:
folder=folder-name&expires=3600(expires is optional) - Returns pre-signed URLs for all files in the specified folder
- Fork the repository.
- Create a new branch (
git checkout -b feature-name). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-name). - Create a new pull request.
This project is licensed under the MIT License.