44import okhttp3 .Request ;
55import okhttp3 .RequestBody ;
66
7- import javax .activation .MimetypesFileTypeMap ;
87import java .io .IOException ;
98import java .math .BigDecimal ;
109import java .nio .file .Files ;
1110import java .nio .file .Path ;
1211import java .util .ArrayList ;
13- import java .util .Arrays ;
12+ import java .util .Collections ;
1413import java .util .List ;
1514import java .util .concurrent .CompletableFuture ;
1615import java .util .concurrent .ExecutionException ;
@@ -53,8 +52,7 @@ public Param(String name, byte[] value, String fileFormat) {
5352 public Param (String name , byte [] value , String fileFormat , Config config ) {
5453 this (name );
5554 String fileName = "getFile." + fileFormat ;
56- String contentTypeString = MimetypesFileTypeMap .getDefaultFileTypeMap ().getContentType (fileName );
57- this .value = upload (value , fileName , MediaType .parse (contentTypeString ), config );
55+ this .value = upload (value , fileName , config );
5856 isUploadedFile = true ;
5957 }
6058
@@ -65,8 +63,7 @@ public Param(String name, Path value) throws IOException {
6563 @ SuppressWarnings ("WeakerAccess" )
6664 public Param (String name , Path value , Config config ) throws IOException {
6765 this (name );
68- String contentTypeString = MimetypesFileTypeMap .getDefaultFileTypeMap ().getContentType (value .toFile ());
69- this .value = upload (Files .readAllBytes (value ), value .getFileName ().toString (), MediaType .parse (contentTypeString ), config );
66+ this .value = upload (Files .readAllBytes (value ), value .getFileName ().toString (), config );
7067 isUploadedFile = true ;
7168 }
7269
@@ -87,7 +84,7 @@ public Param(String name, ConversionResult value, int fileIndex) {
8784 @ SuppressWarnings ("WeakerAccess" )
8885 public Param (String name , CompletableFuture <ConversionResult > value , int fileIndex ) {
8986 this (name );
90- this .value = value .thenApply ((res ) -> Arrays . asList (res .getFile (fileIndex ).getUrl ()));
87+ this .value = value .thenApply ((res ) -> Collections . singletonList (res .getFile (fileIndex ).getUrl ()));
9188 }
9289
9390 @ SuppressWarnings ("unused" )
@@ -110,13 +107,13 @@ public CompletableFuture<Void> delete() {
110107 : CompletableFuture .completedFuture (null );
111108 }
112109
113- private static CompletableFuture <List <String >> upload (byte [] data , String fileName , MediaType fileContentType , Config config ) {
110+ private static CompletableFuture <List <String >> upload (byte [] data , String fileName , Config config ) {
114111 return CompletableFuture .supplyAsync (() -> {
115112 Request request = Http .getRequestBuilder ()
116113 .url (Http .getUrlBuilder (config ).addPathSegment ("upload" )
117114 .addQueryParameter ("filename" , fileName )
118115 .build ())
119- .post (RequestBody .create (fileContentType , data ))
116+ .post (RequestBody .create (MediaType . parse ( "application/octet-stream" ) , data ))
120117 .build ();
121118 try {
122119 List <String > valueList = new ArrayList <>();
0 commit comments