@@ -38,7 +38,7 @@ public record Part(String contentType, String filename, String data, File file)
3838
3939 }
4040
41- private record PartMetadata (String name , String filename ) {
41+ private record PartMetadata (String contentType , String name , String filename ) {
4242
4343 }
4444
@@ -120,12 +120,12 @@ public static Map<String, List<Part>> parse(String encoding, String content_type
120120 if (meta .filename == null ) {
121121 var bos = new ByteArrayOutputStream ();
122122 os = bos ;
123- addToResults = () -> results .computeIfAbsent (meta .name , k -> new LinkedList <Part >()).add (new Part (null , null , bos .toString (charset ), null ));
123+ addToResults = () -> results .computeIfAbsent (meta .name , k -> new LinkedList <Part >()).add (new Part (meta . contentType , null , bos .toString (charset ), null ));
124124 } else {
125125 File file = Path .of (storage .toString (), meta .filename ).toFile ();
126126 file .deleteOnExit ();
127127 os = new NoSyncBufferedOutputStream (new FileOutputStream (file ));
128- addToResults = () -> results .computeIfAbsent (meta .name , k -> new LinkedList <Part >()).add (new Part (null , meta .filename , null , file ));
128+ addToResults = () -> results .computeIfAbsent (meta .name , k -> new LinkedList <Part >()).add (new Part (meta . contentType , meta .filename , null , file ));
129129 }
130130
131131 try (os ) {
@@ -170,6 +170,7 @@ public static Map<String, List<Part>> parse(String encoding, String content_type
170170 private static PartMetadata parseHeaders (List <String > headers ) {
171171 String name = null ;
172172 String filename = null ;
173+ String contentType = null ;
173174 for (var header : headers ) {
174175 String [] parts = header .split (":" , 2 );
175176 if ("content-disposition" .equalsIgnoreCase (parts [0 ])) {
@@ -188,9 +189,11 @@ private static PartMetadata parseHeaders(List<String> headers) {
188189 }
189190 }
190191
192+ } else if ("content-type" .equalsIgnoreCase (parts [0 ])) {
193+ contentType = parts [1 ].trim ();
191194 }
192195 }
193- return new PartMetadata (name , filename );
196+ return new PartMetadata (contentType , name , filename );
194197 }
195198
196199 private static String readLine (Charset charset , InputStream is ) throws IOException {
0 commit comments