From 926d4a2b76d4e7a7bc8e2bc510672d59e99ff6ca Mon Sep 17 00:00:00 2001 From: Karsten Hinz Date: Wed, 27 Jul 2016 13:06:05 +0200 Subject: [PATCH 1/4] improved Multipart/form-data file upload support this code will fix #3389 ( change of content Type to MediaType.APPLICATION_OCTET_STREAM_TYPE) + possibility for multi file upload (as List) --- .../src/main/resources/Java/ApiClient.mustache | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index c4e2538b4c3..beb646ec22f 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -497,9 +497,16 @@ public class ApiClient { if (contentType.startsWith("multipart/form-data")) { FormDataMultiPart mp = new FormDataMultiPart(); for (Entry param: formParams.entrySet()) { - if (param.getValue() instanceof File) { + if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty() + && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { + @SuppressWarnings( "unchecked" ) + List files = ( List ) param.getValue(); + for( File file : files ) { + mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); + } + } elseif (param.getValue() instanceof File) { File file = (File) param.getValue(); - mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.MULTIPART_FORM_DATA_TYPE)); + mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } else { mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE); } From 03986761dc0e03ecab193a3e67189d78d365b956 Mon Sep 17 00:00:00 2001 From: Karsten Hinz Date: Tue, 9 Aug 2016 15:06:26 +0200 Subject: [PATCH 2/4] typo eleif zu else if --- .../swagger-codegen/src/main/resources/Java/ApiClient.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index beb646ec22f..5d434c6980b 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -504,7 +504,7 @@ public class ApiClient { for( File file : files ) { mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); } - } elseif (param.getValue() instanceof File) { + } else if (param.getValue() instanceof File) { File file = (File) param.getValue(); mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } else { From 58f00efcc3c8763540c8afa241e29386687041ea Mon Sep 17 00:00:00 2001 From: Karsten Hinz Date: Tue, 9 Aug 2016 15:09:48 +0200 Subject: [PATCH 3/4] sample update --- .../src/main/java/io/swagger/client/ApiClient.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index bf4695d7854..b58449c7c1e 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -509,9 +509,16 @@ public class ApiClient { if (contentType.startsWith("multipart/form-data")) { FormDataMultiPart mp = new FormDataMultiPart(); for (Entry param: formParams.entrySet()) { - if (param.getValue() instanceof File) { + if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty() + && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { + @SuppressWarnings( "unchecked" ) + List files = ( List ) param.getValue(); + for( File file : files ) { + mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); + } + } else if (param.getValue() instanceof File) { File file = (File) param.getValue(); - mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.MULTIPART_FORM_DATA_TYPE)); + mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } else { mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE); } From 1c9c2eb09c80fa03cc2b1c6764dcdc1f07078f58 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 12 Aug 2016 15:37:31 +0800 Subject: [PATCH 4/4] update java jersey1 sample --- .../src/main/java/io/swagger/client/ApiClient.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index eb1eb5ff505..c3d9ef3457a 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -510,12 +510,12 @@ public class ApiClient { FormDataMultiPart mp = new FormDataMultiPart(); for (Entry param: formParams.entrySet()) { if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty() - && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { - @SuppressWarnings( "unchecked" ) - List files = ( List ) param.getValue(); - for( File file : files ) { - mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); - } + && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { + @SuppressWarnings( "unchecked" ) + List files = ( List ) param.getValue(); + for( File file : files ) { + mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); + } } else if (param.getValue() instanceof File) { File file = (File) param.getValue(); mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE));