Das Problem tritt auf, wenn ich meiner Anfrage eine 92-MB-Datei hinzufüge. Wenn ich diese Datei hinzufüge, benötigt OKHTTP etwa 1 Minute, um die Anfrage an mein Backend zu senden.
Hat jemand schon Erfahrungen gemacht oder weiß, warum es so lange dauert, die Anfrage zu senden?
P.S. Ich habe einen angepassten Code angehängt, der dem ähnelt, den ich verwende, aber ich glaube wirklich, dass das etwas mit internem Caching oder Komprimieren zu tun hat.
Code: Select all
HttpUrl httpUrl = new HttpUrl.Builder()
.scheme(BackendEndpointConstants.PROTOCOL)
.host(BackendEndpointConstants.HOST)
.port(Integer.valueOf(BackendEndpointConstants.PORT))
.addPathSegment(BackendEndpointConstants.BASE_ENDPOINT)
.addPathSegment(BackendEndpointConstants.BASE_ENDPOINT_VERSION)
.addPathSegment(BackendEndpointConstants.ATTACHMENTS)
.build();
MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder();
multipartBodyBuilder.addFormDataPart("fileDescription", JSONUtils.toString(uploadFileDescriptor));
File fileAttachment = basePath.resolve(fileAtachmentDTO.getPathToFile()).toFile();
multipartBodyBuilder.setType(MultipartBody.FORM);
multipartBodyBuilder.addFormDataPart("files[]", fileAttachment.getName(), RequestBody.create(fileAttachment, MediaType.parse(fileAttachmentDTO.getMimeType())));
MultipartBody multipartBody = multipartBodyBuilder.build();
Request request = new Request.Builder()
.addHeader("Authorization", "Bearer " + userApiToken)
.url(httpUrl)
.post(multipartBody)
.build();
OkHttpClient client = new OkHttpClient.Builder().writeTimeout(10, TimeUnit.MINUTES).readTimeout(1, TimeUnit.MINUTES).build();
try (okhttp3.Response response = client.newCall(request).execute()) {
String responseBody = response.body().string();
} catch (IOException e) {
Log.e(TAG, "Error", e);
throw new RuntimeException(e);
}