Skip to content

imash96/r2-uploader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare R2 Uploader

A robust, reusable TypeScript uploader for Cloudflare R2 that works with both Bun.js and Node.js.

Features

  • ✅ Upload files and folders to Cloudflare R2
  • ✅ Compatible with both Bun.js and Node.js
  • ✅ Automatic content-type detection
  • ✅ Directory prefix support for organization
  • ✅ Public URL generation
  • ✅ CSV result exports
  • ✅ Comprehensive error handling
  • ✅ Reusable as a module

Prerequisites

  • Bun.js (v1.0+) or Node.js (v18+)
  • A Cloudflare account with R2 enabled

Setup Cloudflare R2

1. Create an R2 Bucket

  1. Log in to your Cloudflare Dashboard
  2. Navigate to R2 Object Storage
  3. Click Create bucket
  4. Enter a unique bucket name (e.g., my-uploads)
  5. Select your preferred location (or use Automatic)
  6. Click Create bucket

2. Enable Public Access (Optional)

To make uploaded files publicly accessible:

Option A: R2.dev Subdomain (Development)

  1. Go to your bucket settings
  2. Under Public Development URL, click Enable
  3. Type allow to confirm
  4. Your public URL will be: https://{bucket-name}.{account-id}.r2.dev

Option B: Custom Domain (Production)

  1. In bucket settings, go to Custom Domains
  2. Click Add and enter your domain
  3. Cloudflare will create the necessary DNS records
  4. Use your custom domain as R2_PUBLIC_URL in .env

3. Generate API Credentials

  1. In the R2 dashboard, click Manage R2 API Tokens
  2. Click Create API Token
  3. Configure the token:
    • Token Name: r2-uploader
    • Permissions: Select Object Read and Write
    • Bucket: Choose your bucket or All buckets
  4. Click Create API Token
  5. IMPORTANT: Copy the Access Key ID and Secret Access Key immediately (they won't be shown again)
  6. Note your Account ID (visible in the dashboard URL or R2 overview)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors