7

I have a servlet which is able to receive binary data [files].

I would like to use Spring's RestTemplate() to upload a large binary file to the servlet. However its not possible to load the binary file entirely into memory.

So far my attempts have resulted in OutOfMemory errors, indicating the methods have been attempting to load the entire file into memory.

How can I stream this binary data to the servlet? Preferable in Spring or otherwise in Java.

1 Answer 1

15

Found the answer:

https://jira.springsource.org/browse/SPR-7909



SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
RestTemplate rest = new RestTemplate(requestFactory);

This prevents loading the entire request into memory.

Sign up to request clarification or add additional context in comments.

2 Comments

Notice that this is fixed as of Spring version 3.1. So this problem should no longer arise if you are using Spring version >= 3.1. Otherwise, the code snippet above should solve the problem.
@Doron : I use Spring 3.2.5 but I met the same issue, i'm not sure that It was fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.