Using Spring Rest Template to upload a 100 MB file, using a multipart post request.
Client Code:
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("name", chunk.getFilename());
map.add("filename", chunk.getFilename());
map.add("flowChunkNumber", chunk.getNumber());
map.add("flowChunkSize", chunkSize);
map.add("flowIdentifier", chunk.getIdentifier());
map.add("flowTotalSize", chunk.getTotalSize());
map.add("flowCurrentChunkSize", chunk.getSize());
map.add("file", chunk.getResource() );
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(map, headers);
ResponseEntity<String> response = executeForResponse(
baseUri().path("/api/v1/uploads/chunks")
.build().toUri(), HttpMethod.POST, entity, String.class);
However the server ( Springs Boot application deployed on Amazon AWS ) returns :
org.springframework.web.client.HttpClientErrorException: 413 Request Entity Too Large
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:466)
Strangely enough I can upload the same file using an angular JS code to the same Spring Boot application.
Though in angular code I use : forceChunkSize : true
Can I do the same in java ?