Nirmos
Platform setup

Private media assets

Upload directly to S3, verify image content, and retrieve temporary downloads.

Media assets represent uploaded and generated images in your organization. Files stay in private S3; MongoDB stores metadata and relationships. Asset metadata responses omit bucket names, object keys, and internal storage errors. Signed upload form fields and download URLs are temporary access credentials: keep them out of logs and browser persistence.

Direct upload

The SDK uses your API origin for metadata operations. Uploading requires media:create; metadata/download reads require media:read, and deletion requires media:delete. This browser-compatible helper accepts a Blob or File and needs no AWS credentials:

async function storeProduct(file: File) {
  const asset = await nirmos.media.upload(file, { filename: file.name });
  console.log(asset.id, asset.width, asset.height);
  return asset;
}

Pass the File selected by your file input. For explicit control, request a signed form, send the file directly to S3, then complete verification:

async function uploadProduct(file: File) {
  const upload = await nirmos.media.createUpload({
    filename: "product.png",
    contentType: "image/png",
    sizeBytes: file.size,
  });
  const form = new FormData();
  for (const [key, value] of Object.entries(upload.fields)) form.append(key, value);
  form.append("file", file, "product.png");
  const sent = await fetch(upload.uploadUrl, {
    method: upload.method,
    body: form,
    credentials: "omit",
    redirect: "error",
  });
  if (!sent.ok) throw new Error("S3 upload failed");
  return nirmos.media.completeUpload({ assetId: upload.assetId });
}

Do not set multipart Content-Type manually; the browser supplies its boundary. Do not forward Nirmos API keys or cookies to S3. Form fields must be preserved exactly. HTTP management requests use camel-case JSON fields, matching these SDK examples.

Verification and lifecycle

An asset starts PENDING. Presigned POST conditions enforce the declared size and MIME. Completion verifies object size, MIME, image signature, full pixel decoding, dimensions, and SHA-256 checksum. Filenames must have an extension matching PNG, JPEG, or WebP. Animated, corrupt, oversized, expired, or forged uploads fail verification.

Completion promotes the verified staged version to a separate final key before marking READY. Without S3 versioning, the backend uploads the bytes it verified to that final key, preventing an ETag collision or replacement from changing verified content. Reusing the upload authorization cannot overwrite that final object. READY completion is idempotent; concurrent verification returns 409 and can be retried. A missing upload can be retried after the direct transfer, until the upload expires.

Retrieve and download

const page = await nirmos.media.list({ limit: 20, sourceType: "UPLOAD" });
for (const asset of page.items) {
  const detail = await nirmos.media.get(asset.id);
  const download = await nirmos.media.getDownloadUrl(asset.id);
  console.log(detail.mimeType, download.url, download.expiresAt);
}
if (page.nextCursor) {
  const nextPage = await nirmos.media.list({ cursor: page.nextCursor, limit: 20 });
  console.log(nextPage.items);
}

Request fresh URLs when they expire. Signed downloads grant temporary bearer access to the object and can expire earlier when the signing role session expires. Do not store them as canonical links. Organization ownership is checked for metadata, completion, downloads, listing cursors, and deletion.

media.delete(id) hides an unreferenced asset immediately and attempts object cleanup. Storage failures leave an operator-retryable cleanup manifest. Assets referenced by generations return 409 ASSET_IN_USE, preserving generation history. Generated assets are retained until an explicit retention/erasure procedure is implemented.

S3 setup and maintenance · Image generation · Media SDK reference

Organization deletion returns MEDIA_CLEANUP_REQUIRED while retained assets or unfinished cleanup exist. This guard also covers native Better Auth deletion, preserving storage manifests. Uploaded assets can be deleted through the media API; generated media requires an operator retention/erasure procedure.

On this page