@@ -10,6 +10,7 @@ import {
1010 HeadObjectCommand ,
1111 AbortMultipartUploadCommand ,
1212 type StorageClass ,
13+ type CompleteMultipartUploadCommandInput ,
1314} from '@aws-sdk/client-s3' ;
1415import { Upload } from '@aws-sdk/lib-storage' ;
1516import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
@@ -36,6 +37,16 @@ const normalizeHref = (href: string) => {
3637 return href . split ( '?' ) [ 0 ] ;
3738} ;
3839
40+ export const supportedChecksumAlgorithms = [
41+ 'CRC32' ,
42+ 'CRC32C' ,
43+ 'CRC64NVME' ,
44+ ] as const ;
45+ export type SupportedChecksumAlgorithm =
46+ ( typeof supportedChecksumAlgorithms ) [ number ] ;
47+
48+ type ChecksumParamName = `Checksum${SupportedChecksumAlgorithm } `;
49+
3950export class S3Handler implements webResourceHandler . WebResourceHandler {
4051 private readonly config : S3ClientConfig ;
4152 private readonly bucket : string ;
@@ -95,6 +106,11 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
95106 ContentDisposition : `inline; filename="${ resource . originalname } "` ,
96107 StorageClass : this . storageClass ,
97108 } ;
109+
110+ if ( resource . checksumAlgorithm != null ) {
111+ const headerValue = this . getS3ChecksumHeader ( resource . checksumAlgorithm ) ;
112+ params [ headerValue ] = resource . checksum ;
113+ }
98114 const upload = new Upload ( { client : this . client , params } ) ;
99115
100116 upload . on ( 'httpUploadProgress' , async ( ev ) => {
@@ -175,15 +191,22 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
175191 uploadId,
176192 filename,
177193 providerCommitData,
194+ checksumAlgorithm,
195+ checksum,
178196 } : webResourceHandler . CommitMultipartUploadPayload ) : Promise < WebResource > => {
179- await this . client . send (
180- new CompleteMultipartUploadCommand ( {
181- Bucket : this . bucket ,
182- Key : fileKey ,
183- UploadId : uploadId ,
184- MultipartUpload : providerCommitData ,
185- } ) ,
186- ) ;
197+ const params : CompleteMultipartUploadCommandInput = {
198+ Bucket : this . bucket ,
199+ Key : fileKey ,
200+ UploadId : uploadId ,
201+ MultipartUpload : providerCommitData ,
202+ } ;
203+
204+ if ( checksumAlgorithm != null ) {
205+ const headerValue = this . getS3ChecksumHeader ( checksumAlgorithm ) ;
206+ params [ headerValue ] = checksum ;
207+ }
208+
209+ await this . client . send ( new CompleteMultipartUploadCommand ( params ) ) ;
187210
188211 const headResult = await this . client . send (
189212 new HeadObjectCommand ( {
@@ -244,6 +267,12 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
244267 return `${ fieldName } _${ randomUUID ( ) } ` ;
245268 }
246269
270+ private getS3ChecksumHeader (
271+ algorithm : SupportedChecksumAlgorithm ,
272+ ) : ChecksumParamName {
273+ return `Checksum${ algorithm } ` ;
274+ }
275+
247276 private async getUploadParts (
248277 fileKey : string ,
249278 uploadId : string ,
0 commit comments