Skip to content

itsbenkm/cloudflare_worker

Repository files navigation

woodtableguy888 — Image Upload Worker

A Cloudflare Worker that fetches images from a remote URL and stores them directly into an R2 bucket, streaming the response body without buffering.

How it works

  1. Receives a POST request with a JSON body containing a source URL and a destination path
  2. Checks if the file already exists in R2 — skips if so
  3. Fetches the image from the source URL (with optional Referer header)
  4. Streams the image body directly into R2 without loading it into memory

API

Endpoint: POST https://woodtableguy888.imageuploads.workers.dev

Request body:

{
	"url": "https://example.com/image.jpg",
	"path": "folder/filename.jpg",
	"referer": "https://example.com/"
}
Field Type Required Description
url string Yes The source URL to fetch the image from
path string Yes The destination key/path in the R2 bucket
referer string No Referer header to send with the fetch request

Responses:

Status Body Meaning
200 {"status":"stored","path":"..."} Image fetched and saved to R2
200 {"status":"skipped","path":"..."} File already exists in R2
400 "Missing fields" url or path not provided
400 "Invalid JSON" Request body is not valid JSON
405 "POST only" Non-POST request received
500 {"error":"...","status":...} Fetch or R2 error

Example:

curl -X POST https://woodtableguy888.imageuploads.workers.dev \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://photo.yupoo.com/woodtableguy888/da5ccd80/580a0ca1.jpg",
    "path": "test/01.jpg",
    "referer": "https://woodtableguy888.x.yupoo.com/"
  }'

Setup

Prerequisites

  • Node.js
  • A Cloudflare account with an R2 bucket named woodtableguy888

Install dependencies

npm install

Local development

npm run dev

Deploy

npm run deploy

Regenerate TypeScript types (after changing bindings)

npm run cf-typegen

Configuration

Bindings are defined in wrangler.jsonc:

Binding Type Resource
MEDIA_BUCKET R2 Bucket woodtableguy888

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors