Skip to content

ton-github/cloudflare-r2-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC Cloudflare R2 API (Express)

Simple API to upload, download, and generate a preview link (signed URL) for images/files stored in Cloudflare R2.

Setup

  • Install
pnpm install
  • Create .env

This environment blocks dotfiles in the workspace, so copy env.example.env on your machine:

cp env.example .env

Fill your real R2 values in .env.

Run

pnpm dev

Server: http://localhost:3000

Test script (uploads rac-01.jpg and prints signed URL)

In a separate terminal (with server running):

pnpm test:api

Optional:

API_BASE=http://localhost:3000 pnpm test:api

API

  • Health

    • GET /health
  • Upload (multipart)

    • POST /upload
    • form field: file
    • optional: ?key=my-file-name (without extension; extension inferred)

Example:

curl -F "file=@./my-image.jpg" "http://localhost:3000/upload"
  • Download / inline preview
    • GET /download/*
    • Note: :key is the object key returned from upload (including any prefix).
    • Tip: If you set R2_PREFIX=uploads/, the returned key already includes uploads/... — you should pass it exactly as-is.

Example:

curl -L "http://localhost:3000/download/uploads/12345-abcd.jpg" --output out.jpg
  • Get signed preview link
    • GET /preview/*
    • optional: ?expiresIn=3600

Example:

curl "http://localhost:3000/preview/uploads/12345-abcd.jpg"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors