简体   繁体   中英

OutOfMemoryError while renaming multipartFile

I need to rename a mutipartFile before uploading it.

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

Is there another solution?

My code is :

multipartFile = new MockMultipartFile(mf.getName(), "nomFichier", mf.getContentType(),mf.getBytes());

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM