dimah-s3v1.5.5

Download Hooks

Authorize and sign GET download URLs or proxy streams.

Enable download operations with download: true or a DownloadConfig object on a named route.

lib/s3.ts
import { S3Client } from "@aws-sdk/client-s3";
import { dimahS3, errors, route } from "@dimah-s3/server";

export const awsS3 = new S3Client({/* env */});

export const s3 = dimahS3({
  client: awsS3,
  bucket: process.env.S3_BUCKET!,
  routes: {
    avatar: route({
      download: {
        disposition: "inline",
        guard: async ({ key, request }) => {
          const session = await getSession(request);
          if (!session) throw errors.unauthorized();
        },
      },
    }),
  },
});

Download lifecycle flow

Download flow
  1. download.resolvehook
  2. download.guardhook
  3. onPresignedhook
  4. Fetch from S3S3
  1. resolve: Optionally rewrites download fileName, disposition (inline vs attachment), or expiresIn.
  2. guard: Validates request permissions for the specified key.
  3. onPresigned: Receives the signed URL and expiration details.

Type reference

import type {
  DownloadGuardContext,
  DownloadOnPresignedContext,
  DownloadResolveInfo,
} from "@dimah-s3/server";

DownloadGuardContext

Prop

Type


DownloadOnPresignedContext

Prop

Type


DownloadResolveInfo

Prop

Type

Frequently asked questions

On this page