Download
Download hooks for auth and presigned GET URLs.
Enable download in config before these hooks run:
download: { enabled: true },Flow: presignGuard → onPresigned
Presign guard
download: {
enabled: true,
presignGuard: async ({ key, bucket }) => {
// check the user can access this key
},
},DownloadPresignGuardContext
Prop
Type
import type { DownloadPresignGuardContext } from "@dimah-s3/server";On presigned
download: {
enabled: true,
onPresigned: async ({ key, url }) => {
console.log(`download: ${key} → ${url}`);
},
},DownloadOnPresignedContext
Prop
Type
import type { DownloadOnPresignedContext } from "@dimah-s3/server";Example
import { dimahS3 } from "@dimah-s3/server";
import { s3Client, defaultBucket } from "@/lib/s3-client";
export const s3 = dimahS3({
s3: s3Client,
defaultBucket,
download: {
enabled: true,
presignGuard: async ({ key, bucket }) => {
// authorize download
},
onPresigned: async ({ key, url }) => {
console.log(`download: ${key} → ${url}`);
},
},
upload: { enabled: true },
delete: { enabled: true },
});