The OkHttp3ClientHttpRequestFactory caches the request body. When the request body is too large, an OOM occurs. The RestTemplate is:

  OkHttp3ClientHttpRequestFactory factory =
                new OkHttp3ClientHttpRequestFactory(new OkHttpClient());
            RestTemplate   restTemplate = new RestTemplate(factory);

But when i user OkHttp3Clientto upload this file, it is successful.

My question is why the SimpleClientHttpRequestFactory can set bufferRequestBody?

    @Override
    public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
        prepareConnection(connection, httpMethod.name());

        if (this.bufferRequestBody) {
            return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
        }
        else {
            return new SimpleStreamingClientHttpRequest(connection, this.chunkSize, this.outputStreaming);
        }
    }

but OkHttp3ClientHttpRequestFactory without this switch?

I want to use the OkHttp3ClientHttpRequestFactory object without caching the request body,How can I do it?

Comment From: hision

@DInTheName I have also encountered this problem. Have you found a solution?

Comment From: snicoll

In the meantime, OkHttp3ClientHttpRequestFactory has been deprecated so I am afraid this issue should be closed for consistency.