pages-direct-upload
Deploy static files to Cloudflare Pages using the Direct Upload API, from anywhere fetch exists. Files go in as in-memory strings or Uint8Arrays, so it runs inside a Cloudflare Worker, where wrangler and the older uploader packages don’t.
One dependency (@noble/hashes for BLAKE3). About 17 KB minified, 7 KB gzipped, with the hashing included.
By ProfessionalFlare.
The existing Direct Upload packages read files from disk and import Node built-ins at the top level, so they fail to bundle for a Workers target. pages-direct-upload takes the files as data and uses only fetch, FormData, Blob, and TextEncoder.
It also handles the parts of the flow that are easy to get wrong:
- Skips files Cloudflare already has, so redeploys only upload what changed.
- Batches uploads and sends them in parallel.
- Retries transient failures and refreshes the upload token when it expires.
- Sends
_headersand_redirectsthe way Pages expects them. - Can check whether a deployment is already in progress, for scheduled deploys that might overlap.
Install
Section titled “Install”npm install pages-direct-uploadRequires Node 20+ or any runtime with fetch, FormData, and Blob.
Quick start
Section titled “Quick start”import { deployFiles } from "pages-direct-upload";
const result = await deployFiles( { "index.html": "<h1>hello</h1>", "data/config.json": JSON.stringify({ ok: true }), }, { accountId: env.CF_ACCOUNT_ID, projectName: "my-site", apiToken: env.CF_API_TOKEN, branch: "main", });
console.log(result.url);The Pages project must already exist. Create an API token with Account → Cloudflare Pages → Edit.
deployFiles returns once the deployment is created, not once it is live. See Examples for how to wait for it.
Where it runs
Section titled “Where it runs”| Runtime | Supported |
|---|---|
| Cloudflare Workers | Yes |
| Node 20+ | Yes |
| Browsers | Only through a proxy, because Cloudflare’s API does not send CORS headers. Point baseUrl at your own proxy. |
See API for the full reference and Examples for Worker, Node, and error-handling walkthroughs.