@@ -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,9 @@ const normalizeHref = (href: string) => {
3637 return href . split ( '?' ) [ 0 ] ;
3738} ;
3839
40+ type ChecksumParamName =
41+ `Checksum${webResourceHandler . SupportedChecksumAlgorithm } `;
42+
3943export class S3Handler implements webResourceHandler . WebResourceHandler {
4044 private readonly config : S3ClientConfig ;
4145 private readonly bucket : string ;
@@ -95,6 +99,11 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
9599 ContentDisposition : `inline; filename="${ resource . originalname } "` ,
96100 StorageClass : this . storageClass ,
97101 } ;
102+
103+ if ( resource . checksumAlgorithm != null ) {
104+ const headerValue = this . getS3ChecksumHeader ( resource . checksumAlgorithm ) ;
105+ params [ headerValue ] = resource . checksum ;
106+ }
98107 const upload = new Upload ( { client : this . client , params } ) ;
99108
100109 upload . on ( 'httpUploadProgress' , async ( ev ) => {
@@ -175,15 +184,22 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
175184 uploadId,
176185 filename,
177186 providerCommitData,
187+ checksumAlgorithm,
188+ checksum,
178189 } : 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- ) ;
190+ const params : CompleteMultipartUploadCommandInput = {
191+ Bucket : this . bucket ,
192+ Key : fileKey ,
193+ UploadId : uploadId ,
194+ MultipartUpload : providerCommitData ,
195+ } ;
196+
197+ if ( checksumAlgorithm != null ) {
198+ const headerValue = this . getS3ChecksumHeader ( checksumAlgorithm ) ;
199+ params [ headerValue ] = checksum ;
200+ }
201+
202+ await this . client . send ( new CompleteMultipartUploadCommand ( params ) ) ;
187203
188204 const headResult = await this . client . send (
189205 new HeadObjectCommand ( {
@@ -244,6 +260,12 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
244260 return `${ fieldName } _${ randomUUID ( ) } ` ;
245261 }
246262
263+ private getS3ChecksumHeader (
264+ algorithm : webResourceHandler . SupportedChecksumAlgorithm ,
265+ ) : ChecksumParamName {
266+ return `Checksum${ algorithm } ` ;
267+ }
268+
247269 private async getUploadParts (
248270 fileKey : string ,
249271 uploadId : string ,
0 commit comments