TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/betterspacx/app/llms.txt
Use this file to discover all available pages before exploring further.
/api/export route offloads image compression to the server using Sharp. Most Betterflow exports happen entirely in the browser (the canvas is composited with html2canvas and Konva, then converted to a Blob), but the browser’s canvas.toBlob('image/jpeg') encoder cannot match the compression efficiency of native libraries. By sending the raw PNG canvas output to this route, the editor can produce:
- JPEG via MozJPEG — typically 10–15 % smaller than browser JPEG at the same quality setting
- WebP via libwebp — consistently smaller than browser WebP
- PNG via zlib with adaptive filtering — optimal lossless compression
multipart/form-data so the raw image binary never needs to be base64-encoded for transit.
Endpoint
| Property | Value |
|---|---|
| Method | POST |
| Path | /api/export |
| Content-Type | multipart/form-data |
Request Body (Form Fields)
The raw image file to compress. Typically the PNG output of the client-side compositing pipeline. Any format readable by Sharp is accepted as input.
Output format. Must be one of
"png", "jpeg", or "webp".Quality level. Must be one of
"high", "medium", or "low". See the quality table below for the numeric settings each preset maps to.Quality Presets
| Preset | JPEG quality | PNG compression | WebP quality |
|---|---|---|---|
high | 85 | 6 | 82 |
medium | 75 | 9 | 72 |
low | 60 | 9 | 55 |
mozjpeg: true encoder flag.
JPEG does not support transparency. When
format is "jpeg", the route flattens the alpha channel to a white background before encoding. If your design has transparent regions and you want to preserve them, use "png" or "webp".Response
On success the route returns the compressed image binary directly (not JSON) with:Content-Typeset to the appropriate MIME type (image/jpeg,image/webp, orimage/png)Content-Lengthset to the exact byte size of the compressed output
Example
Export Pipeline Context
The full client-side export pipeline that feeds into this route runs as follows:- Background — captured with
html2canvasfrom the CSS-rendered background element - Konva stage — the user image exported at high pixel ratio
- Overlays — text and image overlays captured with
html2canvasin a temporary DOM container - Compositing — all three layers merged onto a single
<canvas>, watermark added - Server compression — the composited PNG is
POSTed to/api/export, and the compressed binary is saved viaIndexedDBand triggered as a browser download
Error Responses
| Status | Description |
|---|---|
400 Bad Request | image file is missing. Returns { "error": "Missing image file" }. |
400 Bad Request | format is not "png", "jpeg", or "webp". Returns { "error": "Invalid format. Must be \"png\", \"jpeg\", or \"webp\"" }. |
400 Bad Request | qualityPreset is not "high", "medium", or "low". Returns { "error": "Invalid qualityPreset. Must be \"high\", \"medium\", or \"low\"" }. |
500 Internal Server Error | Sharp processing failed. Returns { "error": "<Sharp error message>" }. |