@@ -106,12 +106,29 @@ public async Task<UploadResponse> Upload(Stream stream, string filename, JsonSer
106106 using ( var formData = new MultipartFormDataContent ( ) )
107107 {
108108 var fileContent = new StreamContent ( stream ) ;
109- formData . Add ( fileContent , "file" , filename ) ;
110109
111- var uploadResponse = await this . SendAsync ( response . UploadUrl , HttpMethod . Post , attachContent : message =>
110+ var mimeMapping = new Dictionary < string , string >
111+ {
112+ { ".jpg" , "image/jpeg" } ,
113+ { ".jpeg" , "image/jpeg" } ,
114+ { ".png" , "image/png" } ,
115+ { ".tif" , "image/tiff" } ,
116+ { ".tiff" , "image/tiff" } ,
117+ { ".gif" , "image/gif" } ,
118+ { ".svg" , "image/svg+xml" }
119+ } ;
120+
121+ if ( mimeMapping . TryGetValue ( Path . GetExtension ( filename ) . ToLower ( ) , out var mapping ) )
112122 {
113- message . Content = formData ;
114- } ) ;
123+ fileContent . Headers . ContentType = MediaTypeHeaderValue . Parse ( mapping ) ;
124+ }
125+ formData . Add ( fileContent , "file" , filename ) ;
126+
127+ var uploadResponse = await this . SendAsync ( response . UploadUrl , HttpMethod . Post ,
128+ attachContent : message =>
129+ {
130+ message . Content = formData ;
131+ } ) ;
115132 return await uploadResponse . ParseStreamAsync < UploadResponse > ( serializerSettings ) ;
116133 }
117134 }
0 commit comments