2.0 beta is ready. Install with @beta.
dimah-s3v1.7.2
Bring Your Own Backend

Download

Return a signed or proxied download URL from a custom backend.

download returns a GET URL. The default is a short-lived S3 URL. When the route uses download.mode: "proxy", the URL is same-origin and the server streams the body.

The payload is a single object: route, key, and optional fileName, disposition, and expiresIn. expiresIn is a requested TTL in seconds. Sign the shorter of that value and your route cap. Return the TTL you actually signed.

Prop

Type

Prop

Type

import type { DownloadPayload, DownloadPresignResponse } from "@dimah-s3/core";

Example

Add this to the defineApi skeleton. @dimah-s3/server uses GET /api/s3/presign/download?route=…&key=….

async download(payload) {
  const params = new URLSearchParams({
    route: payload.route,
    key: payload.key,
  });
  if (payload.fileName) params.set("fileName", payload.fileName);
  if (payload.disposition) params.set("disposition", payload.disposition);
  if (payload.expiresIn != null) {
    params.set("expiresIn", String(payload.expiresIn));
  }

  const res = await fetch(`/api/files/presign/download?${params}`);
  if (!res.ok) throw new Error(await res.text());
  return res.json();
}

On this page