Skip to content

Commit b58ecb7

Browse files
committed
Upload content type fix
1 parent 01845de commit b58ecb7

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed
Binary file not shown.

src/com/convertapi/Http.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static CompletableFuture<Void> requestDelete(String url) {
5959
}
6060

6161
static Request.Builder getRequestBuilder() {
62-
String agent = String.format("ConvertAPI-Java/%.1f (%s)", 1.4, System.getProperty("os.name"));
62+
String agent = String.format("ConvertAPI-Java/%.1f (%s)", 1.5, System.getProperty("os.name"));
6363
return new Request.Builder().header("User-Agent", agent);
6464
}
6565
}

src/com/convertapi/Param.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import okhttp3.Request;
55
import okhttp3.RequestBody;
66

7-
import javax.activation.MimetypesFileTypeMap;
87
import java.io.IOException;
98
import java.math.BigDecimal;
109
import java.nio.file.Files;
1110
import java.nio.file.Path;
1211
import java.util.ArrayList;
13-
import java.util.Arrays;
12+
import java.util.Collections;
1413
import java.util.List;
1514
import java.util.concurrent.CompletableFuture;
1615
import 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

Comments
 (0)