Cloudflare R2 + Workers
This flow is simpler than the VRoid Hub OAuth setup, but the client side pattern is similar: the app fetches a file URL and reads the response as an ArrayBuffer.
You should not treat the asset endpoint as a page to open in the browser.
The Worker validates the request, streams the object from R2, and returns bytes to fetch().
Overview
- Create an R2 bucket and upload VRM files.
- Configure a Worker with an R2 binding.
- Expose an internal asset route such as
/assets/*. - Fetch the asset URL from the app and read it as an
ArrayBuffer.
Required Environment Variables
VRM_BUCKET
Optional:
ALLOWED_ORIGINS
Notes:
VRM_BUCKETis the R2 binding name used by the Worker.ALLOWED_ORIGINSis a comma-separated allowlist of exact origins.- If
ALLOWED_ORIGINSis omitted, same-origin requests are allowed.
R2 Bucket Setup
Create a bucket, for example vrm-assets, then upload your VRM files.
Example object keys:
avatars/AvatarSample_A.vrmcharacters/Hero.vrm
Worker Settings
wrangler.toml:
Example addresses:
- R2 bucket:
vrm-assets - Local Worker URL:
http://127.0.0.1:8787/assets/avatars/AvatarSample_A.vrm - Production Worker URL:
https://your-worker.example/assets/avatars/AvatarSample_A.vrm - App-side fetch target:
fetch('https://your-worker.example/assets/avatars/AvatarSample_A.vrm')
Official docs:
- Cloudflare R2: https://developers.cloudflare.com/r2/
- Cloudflare Workers: https://developers.cloudflare.com/workers/
Worker Implementation
src/index.ts:
Route Example
The asset endpoint is an internal URL under /assets/*.
The client calls fetch() and then reads the response as an ArrayBuffer.
Examples:
https://your-worker.example/assets/avatars/AvatarSample_A.vrmhttps://your-worker.example/assets/characters/Hero.vrm
Client-side usage:
Local Development and Deploy
Typical Pitfalls
- Calling the asset URL from the browser as if it were a page instead of fetching it.
- Missing or mismatched
ALLOWED_ORIGINSwhen the app runs on another origin. - Uploading VRM files without a proper
Content-Type. - Using a path that does not match the allowlisted extension or includes traversal patterns.
Quick Test Sequence
- Create the R2 bucket and upload a VRM file.
- Set
VRM_BUCKETandALLOWED_ORIGINS. - Start the Worker locally or deploy it.
- Call the asset URL from the app with
fetch(). - Confirm
response.arrayBuffer()returns the VRM bytes.