Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower memory consumption: SpringSingleMultipartFileWriter #88

Open
mulderga-cgi opened this issue Mar 10, 2020 · 5 comments
Open

Lower memory consumption: SpringSingleMultipartFileWriter #88

mulderga-cgi opened this issue Mar 10, 2020 · 5 comments

Comments

@mulderga-cgi
Copy link

mulderga-cgi commented Mar 10, 2020

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.

@Toparvion
Copy link

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.

@koziolk
Copy link

koziolk commented Jan 13, 2021

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

@tmoreira2020
Copy link

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

@koziolk
Copy link

koziolk commented Feb 6, 2021

Looks like the support for large file isn't there. I'm facing a similar issue with pure OpenFeign described here #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).

@tmoreira2020
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants