-2

I need to rename a mutipartFile before uploading it.

I used MockMultipartFile to rename it but an OutOfMemoryError occurs because it 's a large file and MockMultipartFile loads multipartFile.getBytes().

Is there another solution?

My code is :

multipartFile = new MockMultipartFile(mf.getName(), "nomFichier", mf.getContentType(),mf.getBytes());
Thomas Francois
  • 866
  • 6
  • 21
djosefils
  • 15
  • 1
  • 1
    Possible duplicate of [Test maximum upload file size with MockMultipartFile](https://stackoverflow.com/questions/33667276/test-maximum-upload-file-size-with-mockmultipartfile) – Suule Feb 14 '19 at 15:47
  • 1
    You shouldn't be using `MockMultipartFile` as that is for testing only. The name is part of the form, just send another name. – M. Deinum Feb 14 '19 at 18:35

1 Answers1

0

When dealing with file uploads, especially big ones, files should be processed as streams, for example using MockMultipartFile.getInputStream(). The wrong way to do it is to inhale the whole thing into memory; as using the getBytes() method you described.

Kuikiker
  • 156
  • 13