Overview
Cloudflare R2 is an S3-compatible object storage service that offers zero egress fees, making it cost-effective for applications with high data transfer requirements. It’s integrated with Cloudflare’s global network for optimal performance.Prerequisites
Before configuring Cloudflare R2:- Cloudflare Account - Create an account at cloudflare.com
- R2 Bucket - Create a bucket for your files
- API Token - Generate R2 API credentials
- Domain - Optional custom domain setup
Configuration Steps
1
Create R2 Bucket
In your Cloudflare dashboard:
- Go to R2 Object Storage in the left sidebar
- Click Create bucket
- Enter a unique bucket name (e.g.,
your-app-storage) - Choose location:
- Automatic (recommended) - Cloudflare chooses optimal location
- Specify jurisdiction - For data residency requirements
- Select storage class:
- Standard (recommended) - For objects accessed at least once a month
- Infrequent Access - For objects accessed less than once a month
- Click Create bucket
Bucket names must be globally unique across all Cloudflare accounts and are permanent once created. Choose a name that reflects your application.
By default, buckets are not publicly accessible. You can access objects through the API or by binding the bucket to a Worker. Bucket access can be changed to Public at any time.
2
Generate API Token
Create R2 API credentials:
- Go to R2 Object Storage in the left sidebar
- Click Manage API tokens
- Choose token type:
- Account API token (recommended for production) - Tied to the account, remains active even when you leave the organization
- User API token (for development) - Tied to your user account, becomes inactive if you leave the organization
- Click Create Account API token or Create User API token
- Configure the token:
- Token name: Enter a descriptive name (e.g.,
aikeedo-storage) - Permissions: Select Object Read & Write (allows read, write, and list objects in specific buckets)
- Specify bucket(s): Choose Apply to specific buckets only and select your bucket
- TTL: Set to Forever or your preferred duration
- Token name: Enter a descriptive name (e.g.,
- Click Create User API Token (or Create Account API Token)
- Copy the Access Key ID and Secret Access Key from the success page
- Save credentials securely
The endpoint format is:
https://<ACCOUNT_ID>.r2.cloudflarestorage.com/<bucket_name>. You can copy this directly from your R2 bucket settings.3
Configure CORS
Set up CORS for your domain:
- Go to your R2 bucket
- Click Settings tab
- Scroll to CORS Policy section
- Click Edit button
- In the JSON editor, configure the CORS policy:
- Click Save
Replace
yourdomain.com with your actual domain. For development, you can use ["*"] for AllowedOrigins, but this is not recommended for production.4
Configure in Aikeedo
In your admin panel:
- Go to Settings > Cloud storage > Cloudflare R2
- Toggle Status to Enabled
- Enter S3 API Endpoint:
- Go to your R2 bucket settings in Cloudflare dashboard
- Copy the S3 API URL from the General section
- Paste it into the S3 API Endpoint field
- Enter Public access domain:
- Use your custom domain (e.g.,
https://cdn.yourdomain.com) or R2.dev subdomain - Must include the
https://protocol - If you’ve enabled Secure URLs, include the S3 API endpoint here
- Otherwise, URLs will be public
- Use your custom domain (e.g.,
While Cloudflare R2 URLs are publicly accessible by design, Aikeedo ensures security by using hard-to-guess unique addresses for all uploaded files.
- Enter Bucket name: Your R2 bucket name
- Enter Path prefix (optional subfolder)
- Enter Access key ID: Your R2 access key ID
- Enter Secret access key: Your R2 secret access key
- Click Save changes
5
Activate Cloudflare R2
Enable Cloudflare R2 as your storage provider:
- Go to Settings > Storage settings
- In the Adapter dropdown, select Cloudflare R2
- Configure Group files and Secure URLs as needed
- Click Save changes
Configuration Fields
Required fields:- S3 API Endpoint - R2 S3 API endpoint URL (copy from bucket settings General section)
- Public access domain - Public domain for accessing files (must include
https://protocol, use custom domain or R2.dev subdomain) - Bucket name - Name of your R2 bucket
- Access key ID - R2 access key ID for authentication
- Secret access key - R2 secret access key for authentication
- Path prefix - Optional subfolder within your bucket for organizing files
Troubleshooting
Access denied errors:- Verify API token has correct permissions (Object Read & Write recommended)
- Check bucket name matches exactly
- Ensure S3 API endpoint format is correct:
https://<ACCOUNT_ID>.r2.cloudflarestorage.com/<bucket_name> - Verify access keys are valid and not expired
- Check if token is scoped to the correct bucket
- Check CORS configuration in bucket settings using the JSON editor
- Verify allowed origins include your domain (with https://)
- Ensure allowed methods include GET (sufficient for Aikeedo)
- Validate JSON syntax is correct before saving
- Verify bucket name and endpoint are correct
- Check network connectivity to Cloudflare
- Ensure bucket exists and is accessible
- Verify API token permissions are sufficient