【发布时间】:2016-07-04 16:25:12
【问题描述】:
我正在尝试在我的休息服务上发送文件。我正在使用apache httpcomponents 4.3.
它有效,但它使用大约600 MB。总是,如果文件 200 KB 或 15 GB 它使用 RAM 的 600 MB。
如果我删除 addPart - 内存正常。
那么,为什么文件发送会占用这么多内存?
这是我的代码
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
CloseableHttpClient client = clientBuilder.build();
HttpPost post = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addTextBody("jsonData", gson.toJson(dto));
builder.addPart("file", new FileBody(file, ContentType.APPLICATION_OCTET_STREAM));
post.setEntity(builder.build());
HttpResponse response = client.execute(post);
【问题讨论】:
标签: java http httpclient multipartentity