I want to send via Unirest.post() method a large list of objects, but receive an error "unirest post client intended to send too large body". The list size is about 40,000 entries and consume about 65Mo of memory. The NgInx configuration limit the size to 10Mo and as the size of the list should increase we dont't want to change the NgInx config. I'm looking for a way to send the user list splitted in 10Mo batches using Unirest.post() method.
Actual code is like this and works fine with user list of about 6Mo
public void foo(List<User> users) {
RequestBodyEntity requestBody = Unirest.post(String.format("%s%s", properties.getApiBaseUrl(), "users"))
.header(CONTENT_TYPE, APPLICATION_JSON)
.header(SecurityConstants.HTTP_HEADER_PRINCIPAL, properties.getUserName())
.header(SecurityConstants.HTTP_HEADER_CREDENTIALS, properties.getPassword())
.body(users);
try {
HttpResponse<JsonNode> response = multipartRequestBody.asJson();
if (response.getStatus() == HttpStatus.OK.value()) {
LOGGER.info("ok");
} else {
LOGGER.error("Unable to send user list : status code: {}, bodyResponse: {}", response.getStatus(), response.getBody());
throw new InternalServerErrorException(new UnsupportedOperationException());
}
} catch (UnirestException e) {
LOGGER.error("Unable to extract user list, e);
throw new InternalServerErrorException(e);
}
}