File tree Expand file tree Collapse file tree 3 files changed +56
-2
lines changed
src/Services/S3/Custom/Transfer/Internal
test/Services/S3/IntegrationTests Expand file tree Collapse file tree 3 files changed +56
-2
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 @@ -348,8 +348,22 @@ private InitiateMultipartUploadRequest ConstructInitiateMultipartUploadRequest(R
348
348
if ( this . _fileTransporterRequest . Metadata != null && this . _fileTransporterRequest . Metadata . Count > 0 )
349
349
initRequest . Metadata = this . _fileTransporterRequest . Metadata ;
350
350
if ( this . _fileTransporterRequest . Headers != null && this . _fileTransporterRequest . Headers . Count > 0 )
351
- initRequest . Headers = this . _fileTransporterRequest . Headers ;
352
-
351
+ {
352
+ foreach ( var headerKey in this . _fileTransporterRequest . Headers . Keys )
353
+ {
354
+ // InitiateMultipartUploadRequest already has its content-type header set.
355
+ // don't copy the Content-Type if it's set already as to not overwrite the original content-type
356
+ if ( string . Equals ( headerKey , HeaderKeys . ContentTypeHeader ) && this . _fileTransporterRequest . IsSetContentType ( ) )
357
+ {
358
+ continue ;
359
+ }
360
+ else
361
+ {
362
+ initRequest . Headers [ headerKey ] = this . _fileTransporterRequest . Headers [ headerKey ] ;
363
+ }
364
+ }
365
+ }
366
+
353
367
return initRequest ;
354
368
}
355
369
Original file line number Diff line number Diff line change 11
11
using Amazon . S3 . Util ;
12
12
using AWSSDK_DotNet . IntegrationTests . Utils ;
13
13
using Amazon . Util ;
14
+ using System . Net . Mime ;
15
+ using System . Runtime . InteropServices . ComTypes ;
14
16
15
17
namespace AWSSDK_DotNet . IntegrationTests . Tests . S3
16
18
{
@@ -1031,6 +1033,33 @@ public void TestZeroLengthDownloadToNonExistingPath()
1031
1033
Assert . IsTrue ( File . Exists ( filePath ) ) ;
1032
1034
}
1033
1035
1036
+ [ TestMethod ]
1037
+ [ TestCategory ( "S3" ) ]
1038
+ public void TestMultipartUploadWithSetContentTypeNotOverwritten ( )
1039
+ {
1040
+ // 20 MB stream
1041
+ var fileName = UtilityMethods . GenerateName ( @"SetContentType" ) ;
1042
+ var path = Path . Combine ( BasePath , fileName ) ;
1043
+ var fileSize = 20 * MEG_SIZE ;
1044
+ UtilityMethods . GenerateFile ( path , 20 * MEG_SIZE ) ;
1045
+ var transferUtilityRequest = new TransferUtilityUploadRequest
1046
+ {
1047
+ BucketName = bucketName ,
1048
+ FilePath = path ,
1049
+ Key = "test-content-type" ,
1050
+ ContentType = MediaTypeNames . Text . Plain ,
1051
+ Headers =
1052
+ {
1053
+ ContentEncoding = "gzip" ,
1054
+ } ,
1055
+ } ;
1056
+ var tu = new TransferUtility ( Client ) ;
1057
+ tu . Upload ( transferUtilityRequest ) ;
1058
+ var downloadPath = path + ".download" ;
1059
+ var metadata = Client . GetObjectMetadata ( new GetObjectMetadataRequest { BucketName = bucketName , Key = "test-content-type" } ) ;
1060
+ Assert . IsTrue ( metadata . Headers . ContentType . Equals ( MediaTypeNames . Text . Plain ) ) ;
1061
+ }
1062
+
1034
1063
#if ASYNC_AWAIT
1035
1064
1036
1065
[ TestMethod ]
You can’t perform that action at this time.
0 commit comments