Cloudflare R2 Setup Guide

:record_button: :card_index_dividers: 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

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

  1. Click “Create bucket”
  2. Bucket name: neteon-media (or your preferred name)
  3. Location: Choose closest to your users (or “Automatic”)
  4. Click “Create bucket”

Step 2: Create R2 API Token

2.1 Navigate to API Tokens

  1. In R2 dashboard, click on your bucket name (neteon-media)
  2. Click “Settings” tab
  3. Scroll to “R2 API Tokens” section
  4. Click “Create API token”

2.2 Configure Token Permissions

  1. Token name: neteon-ai-access
  2. Permissions:
    - Object Read & Write (for uploading/downloading files)
  3. TTL: Leave as default or set to “Forever”
  4. Click “Create API Token”

2.3 Copy Credentials
You’ll see:
Access Key ID: xxxxxxxxxxxxxxxxxxxxx
Secret Access Key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

:warning: IMPORTANT: Save these immediately! The secret key is only shown once.


Step 3: Get R2 Endpoint Information

3.1 Find Your Account ID

  1. In Cloudflare dashboard, look at the URL
  2. It will be: https://dash.cloudflare.com/{ACCOUNT_ID}/r2/overview
  3. Copy the Account ID (it’s a long alphanumeric string)

3.2 Get Bucket Endpoint

  1. Go to your bucket settings
  2. Find “S3 API Endpoint”
  3. 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

  1. In bucket settings, click “Public access” tab
  2. Click “Allow Access” or “Connect Domain”

Option A: Use R2.dev Subdomain (Easiest)

  1. Click “Allow Access”
  2. Check “Enable R2.dev subdomain”
  3. You’ll get a URL like: https://pub-xxxxxxxxxxxxx.r2.dev
  4. Copy this URL - this is your R2_PUBLIC_BASE_URL

Option B: Use Custom Domain

  1. Click “Connect Domain”
  2. Enter your domain (e.g., cdn.neteon.ai)
  3. Follow DNS setup instructions
  4. Use your custom domain as R2_PUBLIC_BASE_URL

Step 5: Update Your .env.local

:record_button: Read(.env.local)
⎿ Read 20 lines (ctrl+o to expand)

:record_button: 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