Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(pump): stop 413s on token-image uploads in the launch flows

nirholas03559bd28aa9
diff --git a/public/studio/launch-panel.js b/public/studio/launch-panel.js
index 675078005..bbcf23163 100644
--- a/public/studio/launch-panel.js
+++ b/public/studio/launch-panel.js
@@ -61,6 +61,44 @@ function fileToDataUrl(file) {
});
}
+// Token images travel to /api/pump/build-metadata as base64 JSON, which
+// inflates raw bytes by 4/3. Files at or under this size always fit the API's
+// 4 MB raw ceiling once encoded, so they ship untouched (this also preserves
+// animated GIFs). Anything larger is downscaled in the browser rather than
+// rejected. Twin of the helper in src/pump/pump-modals.js (the two launch
+// surfaces are bundled separately and cannot share a module).
+const IMAGE_PASSTHROUGH_BYTES = 3 * 1024 * 1024;
+const IMAGE_MAX_DIM = 1024;
+
+async function downscaleTokenImage(file) {
+ let bitmap;
+ try {
+ bitmap = await createImageBitmap(file);
+ } catch {
+ return null;
+ }
+ const scale = Math.min(1, IMAGE_MAX_DIM / Math.max(bitmap.width, bitmap.height));
+ const canvas = document.createElement('canvas');
+ canvas.width = Math.max(1, Math.round(bitmap.width * scale));
+ canvas.height = Math.max(1, Math.round(bitmap.height * scale));
+ canvas.getContext('2d').drawImage(bitmap, 0, 0, canvas.width, canvas.height);
+ bitmap.close?.();
+ const encode = (type, quality) => new Promise((r) => canvas.toBlob(r, type, quality));
+ // PNG first to keep transparency; JPEG only when PNG is still too big.
+ let blob = await encode('image/png');
+ if (!blob || blob.size > IMAGE_PASSTHROUGH_BYTES) {
+ for (const quality of [0.92, 0.85, 0.75]) {
+ const jpeg = await encode('image/jpeg', quality);
+ if (jpeg) blob = jpeg;
+ if (jpeg && jpeg.size <= IMAGE_PASSTHROUGH_BYTES) break;
+ }
+ }
+ if (!blob || blob.size > IMAGE_PASSTHROUGH_BYTES) return null;
+ const base = (file.name || 'token').replace(/\.[^.]+$/, '');
+ const ext = blob.type === 'image/jpeg' ? 'jpg' : 'png';
+ return new File([blob], `${base}.${ext}`, { type: blob.type });
+}
+
function friendlyError(msg) {
const m = String(msg || '');
if (/user rejected|rejected the request/i.test(m)) return 'Wallet signing cancelled.';
@@ -984,15 +1022,19 @@ export function mountLaunchPanel(container, { getAvatar, getUser, getPreviewView
if (el) { el.textContent = s.imageError; el.hidden = !s.imageError; }
}
- function handleImageFile(file) {
+ async function handleImageFile(file) {
if (!file) return;
if (!file.type.startsWith('image/')) {
setImageError('That file is not an image. Use a PNG, JPG, GIF, or WebP.');
return;
}
- if (file.size > 4 * 1024 * 1024) {
- setImageError('Image must be under 4 MB. Resize it and try again.');
- return;
+ if (file.size > IMAGE_PASSTHROUGH_BYTES) {
+ setImageError('Optimizing image…');
+ file = await downscaleTokenImage(file);
+ if (!file) {
+ setImageError('Could not shrink that image under 4 MB. Use a smaller one.');
+ return;
+ }
}
setImageError('');
s.imageFile = file;
diff --git a/server/README.md b/server/README.md
index e12f6ed1e..211d88cb6 100644
--- a/server/README.md
+++ b/server/README.md
@@ -43,7 +43,9 @@ Handler-facing parity:
- `req.query` merges search params (repeated keys → arrays), dest-rewrite
query params, then route params — later wins, as on Vercel.
- `req.body` is pre-parsed for JSON / urlencoded / `text/*` /
- `application/octet-stream` at Vercel's 4.5 MB limit; multipart and other
+ `application/octet-stream` at an 8 MB limit (Cloud Run's ceiling is 32 MB;
+ the old Vercel-era 4.5 MB limit rejected base64 token images the
+ build-metadata schema allows); multipart and other
types stay unconsumed for raw-stream handlers.
- SSE streams work: compression exempts `text/event-stream` and the server's
idle timeouts are lifted (Cloud Run's request timeout is the real limit).
diff --git a/server/index.mjs b/server/index.mjs
index b61b6c277..55467ee43 100644
--- a/server/index.mjs
+++ b/server/index.mjs
@@ -23,8 +23,8 @@
// - req.query merges URL search params (repeated keys → array), then
// dest-rewrite query params, then route params — later wins, as on Vercel.
// - req.body is pre-parsed for JSON / urlencoded / text / octet-stream at
-// Vercel's 4.5 MB limit; multipart and other types stay unconsumed so
-// upload handlers can read the raw stream.
+// an 8 MB limit (Cloud Run's ceiling is 32 MB); multipart and other types
+// stay unconsumed so upload handlers can read the raw stream.
// - SSE works: compression skips text/event-stream, and the HTTP server's
// idle timeouts are lifted (Cloud Run enforces the real deadline).
//
@@ -41,7 +41,10 @@ const ROOT = path.resolve(__dirname, '..');
const API_ROOT = path.join(ROOT, 'api');
const DIST_ROOT = path.join(ROOT, 'dist');
const PORT = Number(process.env.PORT) || 8080;
-const BODY_LIMIT = '4.5mb'; // Vercel serverless body limit
+// 8 MB fits the 6 M-char base64 token image build-metadata's schema accepts
+// (base64 inflates raw bytes by 4/3, so the old Vercel-era 4.5 MB limit
+// rejected images the schema allowed). Cloud Run's own ceiling is 32 MB.
+const BODY_LIMIT = '8mb';
// ---------------------------------------------------------------------------
// vercel.json route table, split at the {handle: "filesystem"} marker.
diff --git a/src/pump/pump-modals.js b/src/pump/pump-modals.js
index b67be8df0..4dee3922e 100644
--- a/src/pump/pump-modals.js
+++ b/src/pump/pump-modals.js
@@ -445,6 +445,44 @@ function openGovernance({ mint, currentBps }) {
});
}
+// Token images travel to /api/pump/build-metadata as base64 JSON, which
+// inflates raw bytes by 4/3. Files at or under this size always fit the API's
+// 4 MB raw ceiling once encoded, so they ship untouched (this also preserves
+// animated GIFs). Anything larger is downscaled in the browser rather than
+// rejected. Twin of the helper in public/studio/launch-panel.js (the two
+// launch surfaces are bundled separately and cannot share a module).
+const IMAGE_PASSTHROUGH_BYTES = 3 * 1024 * 1024;
+const IMAGE_MAX_DIM = 1024;
+
+async function downscaleTokenImage(file) {
+ let bitmap;
+ try {
+ bitmap = await createImageBitmap(file);
+ } catch {
+ return null;
+ }
+ const scale = Math.min(1, IMAGE_MAX_DIM / Math.max(bitmap.width, bitmap.height));
+ const canvas = document.createElement('canvas');
+ canvas.width = Math.max(1, Math.round(bitmap.width * scale));
+ canvas.height = Math.max(1, Math.round(bitmap.height * scale));
+ canvas.getContext('2d').drawImage(bitmap, 0, 0, canvas.width, canvas.height);
+ bitmap.close?.();
+ const encode = (type, quality) => new Promise((r) => canvas.toBlob(r, type, quality));
+ // PNG first to keep transparency; JPEG only when PNG is still too big.
+ let blob = await encode('image/png');
+ if (!blob || blob.size > IMAGE_PASSTHROUGH_BYTES) {
+ for (const quality of [0.92, 0.85, 0.75]) {
+ const jpeg = await encode('image/jpeg', quality);
+ if (jpeg) blob = jpeg;
+ if (jpeg && jpeg.size <= IMAGE_PASSTHROUGH_BYTES) break;
+ }
+ }
+ if (!blob || blob.size > IMAGE_PASSTHROUGH_BYTES) return null;
+ const base = (file.name || 'token').replace(/\.[^.]+$/, '');
+ const ext = blob.type === 'image/jpeg' ? 'jpg' : 'png';
+ return new File([blob], `${base}.${ext}`, { type: blob.type });
+}
+
// ── Launch wizard ──────────────────────────────────────────────────────────
// formData: { name, symbol, description, initialBuy, feeTier, image (File|null) }
// Steps: 1 = token details (pre-filled) + metadata generation
@@ -459,11 +497,18 @@ function openLaunch({ identity, agentId, avatarId, formData }) {
async function buildMetadata(name, symbol, description) {
let imageDataUrl = null;
if (formData?.image instanceof File) {
+ let imageFile = formData.image;
+ if (imageFile.size > IMAGE_PASSTHROUGH_BYTES) {
+ imageFile = await downscaleTokenImage(imageFile);
+ if (!imageFile) {
+ throw new Error('Token image is too large. Use an image under 4 MB.');
+ }
+ }
imageDataUrl = await new Promise((resolve) => {
const reader = new FileReader();
reader.onload = (e) => resolve(e.target.result);
reader.onerror = () => resolve(null);
- reader.readAsDataURL(formData.image);
+ reader.readAsDataURL(imageFile);
});
}
const descSource = description || formData?.description || identity?.description || '';