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.
Set upload.maxFileSize; the server checks each signed part against the
remaining allowance and sums uploaded part sizes before
CompleteMultipartUpload. If the total size exceeds the limit, the server
aborts the multipart upload and returns PAYLOAD_TOO_LARGE.