|
| 1 | +# Microblog Example: Netlify Background Uploads |
| 2 | + |
| 3 | +This document shows how to generate the canonical microblog example so image uploads run through Netlify Background Functions and Filecoin Onchain Cloud instead of a VPS-hosted upload process. |
| 4 | + |
| 5 | +Relevant files: |
| 6 | +- schema: `apps/example/microblog.schema.json` |
| 7 | +- generated Netlify artifacts: `out/microblog/netlify.toml`, `out/microblog/netlify/functions/` |
| 8 | + |
| 9 | +## 1. Build the microblog app |
| 10 | + |
| 11 | +```bash |
| 12 | +th build apps/example/microblog.schema.json --chain filecoin_calibration --out out/microblog |
| 13 | +``` |
| 14 | + |
| 15 | +Because the schema includes: |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "app": { |
| 20 | + "deploy": { |
| 21 | + "netlify": { |
| 22 | + "uploads": { |
| 23 | + "provider": "filecoin_onchain_cloud", |
| 24 | + "runner": "background-function" |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +the build emits: |
| 33 | +- `out/microblog/netlify.toml` |
| 34 | +- `out/microblog/netlify/functions/tokenhost-upload-start.mjs` |
| 35 | +- `out/microblog/netlify/functions/tokenhost-upload-status.mjs` |
| 36 | +- `out/microblog/netlify/functions/tokenhost-upload-worker-background.mjs` |
| 37 | +- `out/microblog/NETLIFY-UPLOADS.md` |
| 38 | + |
| 39 | +The generated manifest is also wired so the browser upload client talks to: |
| 40 | +- `POST /__tokenhost/upload` |
| 41 | +- `GET /__tokenhost/upload-status?jobId=...` |
| 42 | + |
| 43 | +## 2. Set Netlify environment variables |
| 44 | + |
| 45 | +Set these in Netlify with **Functions** scope: |
| 46 | + |
| 47 | +- `TH_UPLOAD_FOC_PRIVATE_KEY` |
| 48 | +- `TH_UPLOAD_FOC_CHAIN=314159` |
| 49 | +- `TH_UPLOAD_FOC_COPIES=1` |
| 50 | + |
| 51 | +Optional: |
| 52 | + |
| 53 | +- `TH_UPLOAD_FOC_COMMAND=npx -y foc-cli` |
| 54 | +- `TH_UPLOAD_FOC_WITH_CDN=true` |
| 55 | +- `TH_UPLOAD_FOC_DEBUG=true` |
| 56 | + |
| 57 | +Important: |
| 58 | +- runtime secrets must come from Netlify environment variables |
| 59 | +- do not put the private key in `netlify.toml` |
| 60 | + |
| 61 | +## 3. Deploy to Netlify |
| 62 | + |
| 63 | +Deploy the generated build root so Netlify sees: |
| 64 | +- `ui-site/` as the publish directory |
| 65 | +- `netlify/functions/` as the functions directory |
| 66 | + |
| 67 | +The generated `netlify.toml` already configures those paths and the upload redirects. |
| 68 | + |
| 69 | +## 4. Expected runtime flow |
| 70 | + |
| 71 | +1. Browser uploads file bytes to `POST /__tokenhost/upload` |
| 72 | +2. Start function stores the request in Netlify Blobs and returns `202` with `jobId` |
| 73 | +3. Netlify background worker runs `foc-cli upload` |
| 74 | +4. Worker stores success or failure result in Netlify Blobs |
| 75 | +5. Browser polls `/__tokenhost/upload-status?jobId=...` until complete |
| 76 | + |
| 77 | +## Current status |
| 78 | + |
| 79 | +This generated target is meant to remove the VPS requirement for FOC uploads. |
| 80 | + |
| 81 | +What is implemented in Token Host now: |
| 82 | +- schema/build support for a Netlify upload deployment target |
| 83 | +- generated Netlify functions scaffolding |
| 84 | +- manifest/runtime wiring compatible with the existing async browser upload client |
| 85 | + |
| 86 | +What still needs real-world validation: |
| 87 | +- Netlify runtime compatibility for `foc-cli` |
| 88 | +- final deploy ergonomics and any provider-specific edge cases |
0 commit comments