Multipart Hooks
Large-file multipart upload lifecycle, part authorization, and assembly.
Enable multipart support on large-file routes by setting upload.multipart: true or passing a MultipartConfig object.
import { S3Client } from "@aws-sdk/client-s3";
import { dimahS3, route } from "@dimah-s3/server";
export const awsS3 = new S3Client({/* env */});
export const s3 = dimahS3({
client: awsS3,
bucket: process.env.S3_BUCKET!,
routes: {
video: route({
upload: {
fileTypes: ["video/*"],
maxFileSize: 500 * 1024 * 1024, // 500MB
multipart: true,
onConfirmed: async ({ key, contentLength }) => {
// Triggered on successful multipart completion
},
},
}),
},
});Multipart lifecycle flow
- upload.guardInit validation
- CreateMultipartUploadS3
- multipart.guardAuthorizes each part
- CompleteMultipartUploadS3
- HeadObjectserver
- onConfirmedFinal metadata
Type reference
import type {
MultipartConfig,
MultipartOnInitContext,
MultipartGuardContext,
MultipartOnAbortContext,
MultipartOnListContext,
} from "@dimah-s3/server";MultipartConfig
Prop
Type
MultipartOnInitContext
Prop
Type
MultipartGuardContext
Prop
Type
MultipartOnAbortContext
Prop
Type
MultipartOnListContext
Prop
Type
Frequently asked questions
No. The final assembly step (multipart.complete) internally runs upload.confirmGuard, queries HeadObject, and calls upload.onConfirmed.
The server automatically validates each part size during signPart and sums uploaded part sizes before calling CompleteMultipartUpload. If total parts exceed maxFileSize, the upload is aborted with PAYLOAD_TOO_LARGE.