[英]OutOfMemoryError while renaming multipartFile
I need to rename a mutipartFile before uploading it.我需要在上传之前重命名 mutipartFile。
I used MockMultipartFile
to rename it but an OutOfMemoryError
occurs because it 'sa large file and MockMultipartFile
loads multipartFile.getBytes()
.我使用
MockMultipartFile
重命名它,但发生OutOfMemoryError
因为它是一个大文件并且MockMultipartFile
加载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().在处理文件上传时,尤其是大文件,文件应该作为流处理,例如使用 MockMultipartFile.getInputStream()。 The wrong way to do it is to inhale the whole thing into memory;
错误的做法是将整个事情吸入记忆中; as using the getBytes() method you described.
使用您描述的 getBytes() 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.