MarketSupport← Back to app

From Base64 Data

Have base64 data (a canvas export, a data URI, an inline attachment)? Decode and store it on your own storage first, then pass the resulting public URL in input.

Overview

The generation API accepts URLs, not raw base64 payloads — large base64 bodies are slow, hit request-size limits, and can't be retried by the upstream renderer. Persisting the file first is faster and more reliable.

Store it, then reference it

  • Decode the base64 string to bytes.
  • Upload the bytes to your object storage (S3 / OSS / COS / R2) or static file server.
  • Use the file's public (or presigned) URL as the input value.

Node.js example

JavaScript
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({ region: "us-east-1" });

async function base64ToUrl(b64, key) {
  // strip a data-URI prefix if present
  const data = Buffer.from(b64.replace(/^data:.*?;base64,/, ""), "base64");
  await s3.send(new PutObjectCommand({
    Bucket: "my-public-bucket", Key: key,
    Body: data, ContentType: "image/png",
  }));
  return `https://my-public-bucket.s3.amazonaws.com/${key}`;
}

const imageUrl = await base64ToUrl(canvasData, "inputs/photo.png");

await fetch("https://97ai.97claude.com/api/generate", {
  method: "POST",
  headers: { "Authorization": "Bearer " + process.env.API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "google/nano-banana-image-to-image",
    input: { image_url: imageUrl, prompt: "enhance lighting" },
  }),
});