Reputation: 648
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.
Upvotes: 7
Views: 5998
Reputation: 648
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.
Upvotes: 15