Getting Your Cloudflare R2 API Keys

Before you can use the Uploader Template, you need to set up your Cloudflare API keys. This guide will walk you through the process. We will assume you have already set up your Cloudflare account and have a domain name managed in Cloudflare.

  1. Open Cloudflare's dashboard.
  2. Navigate to the R2 Object Storage.
    • Click on the R2 Object Storage tab in the left sidebar.
    Navigating to R2 Object Storage
  3. Create a new API token.
    • Assuming you have already set up your R2 bucket, click on Manage R2 API Tokens.
    Managing R2 API Tokens
    • Click on Create API Token.
    Creating an R2 API Tokens
  4. Configure the API token.
    • Give your token a name and select the permissions you want to grant. In our case Object Read & Write is sufficient.
    • It is recommended to Specify a bucket to limit the token's access.
    Configuring the API Token
    • After configuring the token, scroll down and click on Create API Token.
  5. Copy the Values To Your .env.
    • Copy the Access Key ID, Secret Access Key and jurisdiction endpoint url values to your .env file.
    Copying the API Token Values
    • Your .env file should look like this:
    PORT=":your-port"
    
    CLOUDFLARE_R2_ACCESS_KEY_ID="Access Key ID"
    CLOUDFLARE_R2_SECRET_ACCESS_KEY="Secret Access Key"
    CLOUDFLARE_R2_BUCKET="Your Bucket Name"
    CLOUDFLARE_R2_ENDPOINT="https://12sd3aasd12sd23sd123.r2.cloudflarestorage.com"
    R2_URL="https://r2.example.com"
    
  6. Start the Application.
    • Run the application locally to test your setup:
    go run src/main.go