feign-form icon indicating copy to clipboard operation
feign-form copied to clipboard

Lower memory consumption: SpringSingleMultipartFileWriter

Open mulderga-cgi opened this issue 4 years ago • 5 comments

The write method of SpringSingleMultipartFileWriter.java uses a lot of memory:

@Override
  protected void write (Output output, String key, Object value) throws EncodeException {
    val file = (MultipartFile) value;
    writeFileMetadata(output, key, file.getOriginalFilename(), file.getContentType());

    byte[] bytes;
    try {
      bytes = file.getBytes();
    } catch (IOException ex) {
      throw new EncodeException("Getting multipart file's content bytes error", ex);
    }
    output.write(bytes);
  }

Is it possible to use file.getInputStream() in some kind of way? It will require a lot of refactoring... now large files are loaded inside the memory twice.

mulderga-cgi avatar Mar 10 '20 13:03 mulderga-cgi

Facing the same issue with transferring uploaded files through Feign-equipped applications. It would be much more efficient for memory consumption if Feign could treat uploaded files as byte streams rather than byte arrays.

Toparvion avatar May 12 '20 02:05 Toparvion

Same issue here. Any chance it will be fixed soon?

koziolk avatar Jan 13 '21 20:01 koziolk

Looks like the support for large file isn't there. I'm facing a similar issue with pure OpenFeign described here https://github.com/OpenFeign/feign-form/issues/101 Do you guys found a workaround to this? @Toparvion @mulderga-cgi @koziolk

tmoreira2020 avatar Feb 06 '21 19:02 tmoreira2020

Looks like the support for large file isn't there. I'm facing a similar issue with pure OpenFeign described here https://github.com/OpenFeign/feign-form/issues/101

Do you guys found a workaround to this? @Toparvion @mulderga-cgi @koziolk

Yes. I've written a new client based on RestTemplate from Spring Framwork and was able to stream file content without copying it into a memory. Now I have two clients one for doing uploads and one for other operations (feign).

koziolk avatar Feb 06 '21 19:02 koziolk

Thanks @koziolk for the fast response. I was thinking to do the same approach and have two clients for the short term.

tmoreira2020 avatar Feb 06 '21 21:02 tmoreira2020