@@ -1118,6 +1118,93 @@ public async System.Threading.Tasks.Task UploadAsyncCancellationTest()
11181118 }
11191119#endif
11201120
1121+ [ TestMethod ]
1122+ [ TestCategory ( "S3" ) ]
1123+ public void UploadDirectoryWithMixedFileTypesContentTypeTest ( )
1124+ {
1125+ var directory = CreateMixedFileTypeTestDirectory ( ) ;
1126+ var keyPrefix = directory . Name ;
1127+
1128+ // Upload directory without setting explicit ContentType
1129+ var transferUtility = new TransferUtility ( Client ) ;
1130+ var request = new TransferUtilityUploadDirectoryRequest
1131+ {
1132+ BucketName = bucketName ,
1133+ Directory = directory . FullName ,
1134+ KeyPrefix = keyPrefix ,
1135+ SearchPattern = "*" ,
1136+ SearchOption = SearchOption . AllDirectories
1137+ // Note: No ContentType set - should auto-detect per file
1138+ } ;
1139+
1140+ transferUtility . UploadDirectory ( request ) ;
1141+
1142+ // Validate each file got correct content type based on extension
1143+ ValidateDirectoryContentTypes ( Client , bucketName , keyPrefix , directory ) ;
1144+ }
1145+
1146+ public static DirectoryInfo CreateMixedFileTypeTestDirectory ( )
1147+ {
1148+ var directoryPath = GenerateDirectoryPath ( "MixedFileTypeTest" ) ;
1149+
1150+ var testFiles = new Dictionary < string , string >
1151+ {
1152+ { "test.html" , "<html><body>Test HTML</body></html>" } ,
1153+ { "test.css" , "body { color: red; }" } ,
1154+ { "test.js" , "console.log('test');" } ,
1155+ { "test.json" , "{ \" test\" : \" value\" }" } ,
1156+ { "test.txt" , "Plain text content" } ,
1157+ { "test.xml" , "<?xml version=\" 1.0\" ?><root>test</root>" } ,
1158+ { "test.pdf" , "PDF content placeholder" } ,
1159+ { "test.svg" , "<svg><rect width=\" 100\" height=\" 100\" /></svg>" }
1160+ } ;
1161+
1162+ foreach ( var file in testFiles )
1163+ {
1164+ var filePath = Path . Combine ( directoryPath , file . Key ) ;
1165+ Directory . CreateDirectory ( Path . GetDirectoryName ( filePath ) ) ;
1166+ File . WriteAllText ( filePath , file . Value ) ;
1167+ }
1168+
1169+ return new DirectoryInfo ( directoryPath ) ;
1170+ }
1171+
1172+ private static void ValidateDirectoryContentTypes ( IAmazonS3 s3client , string bucketName , string keyPrefix , DirectoryInfo directory )
1173+ {
1174+ var expectedContentTypes = new Dictionary < string , string >
1175+ {
1176+ { ".html" , "text/html" } ,
1177+ { ".css" , "text/css" } ,
1178+ { ".js" , "application/x-javascript" } ,
1179+ { ".json" , "application/json" } ,
1180+ { ".txt" , "text/plain" } ,
1181+ { ".xml" , "text/xml" } ,
1182+ { ".pdf" , "application/pdf" } ,
1183+ { ".svg" , "image/svg+xml" }
1184+ } ;
1185+
1186+ var files = directory . GetFiles ( "*" , SearchOption . AllDirectories ) ;
1187+ foreach ( var file in files )
1188+ {
1189+ var filePath = file . FullName ;
1190+ var relativePath = filePath . Substring ( directory . FullName . Length + 1 ) ;
1191+ var key = ( ! string . IsNullOrEmpty ( keyPrefix ) ? keyPrefix + "/" : string . Empty ) + relativePath . Replace ( "\\ " , "/" ) ;
1192+
1193+ var metadata = s3client . GetObjectMetadata ( new GetObjectMetadataRequest
1194+ {
1195+ BucketName = bucketName ,
1196+ Key = key
1197+ } ) ;
1198+
1199+ var extension = Path . GetExtension ( file . Name ) . ToLowerInvariant ( ) ;
1200+ var expectedContentType = expectedContentTypes [ extension ] ;
1201+
1202+ Assert . AreEqual ( expectedContentType , metadata . Headers . ContentType ,
1203+ $ "File { file . Name } should have content type { expectedContentType } but got { metadata . Headers . ContentType } ") ;
1204+ }
1205+ }
1206+
1207+
11211208 public static void ConfigureProgressValidator ( DirectoryProgressValidator < DownloadDirectoryProgressArgs > progressValidator )
11221209 {
11231210 progressValidator . Validate = ( progress , lastProgress ) =>
0 commit comments