0

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!

Arzybek
  • 547
  • 2
  • 6
  • 27
  • It looks like Feign doesn't support streaming the uploaded data according to [this SO question from 2015](https://stackoverflow.com/questions/27391234/passing-along-a-data-stream-using-netflix-feign). There [is a bug](https://github.com/OpenFeign/feign/issues/220) on that same topic that's still open suggesting this hasn't change yet (though it might just be open by accident). Streaming the input would be necessary to significantly reduce the memory pressure of this operation. – Joachim Sauer Mar 06 '23 at 12:16
  • @JoachimSauer, and how should I do it then? Is there other similiar http clients or something that is used to workaround? – Arzybek Mar 06 '23 at 12:19
  • https://stackoverflow.com/a/52059099/175554 may help – ozkanpakdil Mar 11 '23 at 21:22

0 Answers0