Cloudflare R2 Setup Guide
Let me walk you through setting up Cloudflare R2 for image and file storage.
Step 1: Create Cloudflare Account & R2 Bucket
1.1 Sign up for Cloudflare
- Go to: https://dash.cloudflare.com/sign-up
- Create an account (free tier available)
- Verify your email
1.2 Enable R2 Storage
- Log in to Cloudflare Dashboard: https://dash.cloudflare.com
- In the left sidebar, click R2
- Click “Purchase R2” or “Get Started”
- Note: R2 has a generous free tier (10GB storage, 1M Class A operations/month)
1.3 Create a Bucket
- Click “Create bucket”
- Bucket name: neteon-media (or your preferred name)
- Location: Choose closest to your users (or “Automatic”)
- Click “Create bucket”
Step 2: Create R2 API Token
2.1 Navigate to API Tokens
- In R2 dashboard, click on your bucket name (neteon-media)
- Click “Settings” tab
- Scroll to “R2 API Tokens” section
- Click “Create API token”
2.2 Configure Token Permissions
- Token name: neteon-ai-access
- Permissions:
- Object Read & Write (for uploading/downloading files) - TTL: Leave as default or set to “Forever”
- Click “Create API Token”
2.3 Copy Credentials
You’ll see:
Access Key ID: xxxxxxxxxxxxxxxxxxxxx
Secret Access Key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
IMPORTANT: Save these immediately! The secret key is only shown once.
Step 3: Get R2 Endpoint Information
3.1 Find Your Account ID
- In Cloudflare dashboard, look at the URL
- It will be: https://dash.cloudflare.com/{ACCOUNT_ID}/r2/overview
- Copy the Account ID (it’s a long alphanumeric string)
3.2 Get Bucket Endpoint
- Go to your bucket settings
- Find “S3 API Endpoint”
- It will look like: https://{ACCOUNT_ID}.r2.cloudflarestorage.com
Step 4: Configure Public Access (Optional but Recommended)
4.1 Enable Public Access for Images
- In bucket settings, click “Public access” tab
- Click “Allow Access” or “Connect Domain”
Option A: Use R2.dev Subdomain (Easiest)
- Click “Allow Access”
- Check “Enable R2.dev subdomain”
- You’ll get a URL like: https://pub-xxxxxxxxxxxxx.r2.dev
- Copy this URL - this is your R2_PUBLIC_BASE_URL
Option B: Use Custom Domain
- Click “Connect Domain”
- Enter your domain (e.g., cdn.neteon.ai)
- Follow DNS setup instructions
- Use your custom domain as R2_PUBLIC_BASE_URL
Step 5: Update Your .env.local
Read(.env.local)
⎿ Read 20 lines (ctrl+o to expand)
Now update your .env.local with the credentials you just got:
Replace these lines in .env.local:
Cloudflare R2 (S3 compatible)
R2_ACCOUNT_ID=your-cloudflare-account-id-here
R2_ACCESS_KEY_ID=your-r2-access-key-id
R2_SECRET_ACCESS_KEY=your-r2-secret-access-key
R2_BUCKET_NAME=neteon-media
R2_PUBLIC_BASE_URL=https://pub-xxxxxxxxxxxxx.r2.dev
Where to find each value:
- R2_ACCOUNT_ID - From Cloudflare dashboard URL
- R2_ACCESS_KEY_ID - From API token creation (looks like: a1b2c3d4e5f6…)
- R2_SECRET_ACCESS_KEY - From API token creation (longer key, only shown once)
- R2_BUCKET_NAME - Your bucket name (e.g., neteon-media)
- R2_PUBLIC_BASE_URL - Your R2.dev subdomain URL