I am to invoke a POST REST API which accepts a file in its body.
If I send a few KB's file (using below code) it takes about 300 ms. And, if i send about 5 GB's of file it throws Out Of Memory Exception.
Is there a possible way to send the file as Chunks, sequentially? We are avoiding any parallel processing, at this point in time.
Any help in code or reference is highly appreciated.
public static Resource getTestFile() throws IOException {
Path testFile = Paths.get(FILE_PATH);
System.out.println("Creating and Uploading Test File: " + testFile);
return new FileSystemResource(testFile.toFile());
}
private static void uploadSingleFile() throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", getTestFile());
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
String serverUrl = "http://localhost:8080/place";
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<DataTransportResponse> response = restTemplate.postForEntity(serverUrl, requestEntity,
DataTransportResponse.class);
System.out.println("Response code: " + response.getStatusCode());
}
spring:
application:
name: file-manager
servlet:
multipart:
max-file-size: 20480MB
max-request-size: 2048MB
application:
seal:
id: 104912