File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
src/Services/S3/Custom/Transfer/Internal
test/Services/S3/IntegrationTests Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "services" : [
3+ {
4+ "serviceName" : " S3" ,
5+ "type" : " patch" ,
6+ "changeLogMessages" : [
7+ " Fix: Fixed a bug where Content-Type header was being overwritten in multipart upload scenarios."
8+ ]
9+ }
10+ ]
11+ }
Original file line number Diff line number Diff line change @@ -354,7 +354,21 @@ private InitiateMultipartUploadRequest ConstructInitiateMultipartUploadRequest(R
354354 if ( this . _fileTransporterRequest . Metadata != null && this . _fileTransporterRequest . Metadata . Count > 0 )
355355 initRequest . Metadata = this . _fileTransporterRequest . Metadata ;
356356 if ( this . _fileTransporterRequest . Headers != null && this . _fileTransporterRequest . Headers . Count > 0 )
357- initRequest . Headers = this . _fileTransporterRequest . Headers ;
357+ {
358+ foreach ( var headerKey in this . _fileTransporterRequest . Headers . Keys )
359+ {
360+ // InitiateMultipartUploadRequest already has its content-type header set.
361+ // don't copy the Content-Type if it's set already as to not overwrite the original content-type
362+ if ( string . Equals ( headerKey , HeaderKeys . ContentTypeHeader ) && this . _fileTransporterRequest . IsSetContentType ( ) )
363+ {
364+ continue ;
365+ }
366+ else
367+ {
368+ initRequest . Headers [ headerKey ] = this . _fileTransporterRequest . Headers [ headerKey ] ;
369+ }
370+ }
371+ }
358372
359373 return initRequest ;
360374 }
Original file line number Diff line number Diff line change 1111using Amazon . S3 . Util ;
1212using AWSSDK_DotNet . IntegrationTests . Utils ;
1313using Amazon . Util ;
14+ using System . Net . Mime ;
1415
1516namespace AWSSDK_DotNet . IntegrationTests . Tests . S3
1617{
@@ -1011,6 +1012,32 @@ public void TestZeroLengthDownloadToNonExistingPath()
10111012 Assert . IsTrue ( File . Exists ( filePath ) ) ;
10121013 }
10131014
1015+ [ TestMethod ]
1016+ [ TestCategory ( "S3" ) ]
1017+ public void TestMultipartUploadWithSetContentTypeNotOverwritten ( )
1018+ {
1019+ // 20 MB stream
1020+ var fileName = UtilityMethods . GenerateName ( @"SetContentType" ) ;
1021+ var path = Path . Combine ( BasePath , fileName ) ;
1022+ var fileSize = 20 * MEG_SIZE ;
1023+ UtilityMethods . GenerateFile ( path , 20 * MEG_SIZE ) ;
1024+ var transferUtilityRequest = new TransferUtilityUploadRequest
1025+ {
1026+ BucketName = bucketName ,
1027+ FilePath = path ,
1028+ Key = "test-content-type" ,
1029+ ContentType = MediaTypeNames . Text . Plain ,
1030+ Headers =
1031+ {
1032+ ContentEncoding = "gzip" ,
1033+ } ,
1034+ } ;
1035+ var tu = new TransferUtility ( Client ) ;
1036+ tu . Upload ( transferUtilityRequest ) ;
1037+ var downloadPath = path + ".download" ;
1038+ var metadata = Client . GetObjectMetadata ( new GetObjectMetadataRequest { BucketName = bucketName , Key = "test-content-type" } ) ;
1039+ Assert . IsTrue ( metadata . Headers . ContentType . Equals ( MediaTypeNames . Text . Plain ) ) ;
1040+ }
10141041#if ASYNC_AWAIT
10151042
10161043 [ TestMethod ]
You can’t perform that action at this time.
0 commit comments