I have a method that accepts the file, does some logic to it and then transfers it to another service's api. I was doing it using feign client, but the problem is that when the file is big (for example 180mb), I get a heap overflow exception. Let's say my method is called /myMethod
, as the input I accept MultipartFile multipartFile
and when I do proccessing of the file in my method, I use InputStream multipartFile.getInputStream()
, so this is not why I get a heap overflow exception.
public private final feignClient;
public void myMethod(MultipartFile multipartFile){
doProcessing(multipartFile.getInputStream); // it's getting closed here, don't worry
feignClient.sendFile(multipartFile);
}
In the exception it says the overflow happens when sending the file to another service's api method, let's call it /anotherServiceMethod
. So I do it using my feign client: feignClient.sendFile(multipartFile)
. So /anotherServiceMethod
also accepts MultipartFile multipartFile
as the input, and I directly send it in the feign client, without modifying it. In the exception it says it couldn't copy the byte[]
and I've read here the feign client in fact does use byte arrays. Feign client looks like this:
public interface FeignClient {
@PostMapping(value = "/anotherServiceMethod", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
void sendFile(@RequestPart(value = "file") MultipartFile file);
...
}
So my question is, how should I send this big file then without getting heap overflow exception? How it is usually done? Isn't multipart file supposed to chop it to chunks? Why is it not working then? Thanks in advance!