@PostMapping("/upload")
public ResultMsg algorithmFile(@RequestParam("file") MultipartFile file) {
String fileName = file.getOriginalFilename();
String[] fileNamePart = fileName.split("\\.");
String fileNameWithPath = filePath + UUID.randomUUID().toString(true) + "."
+ fileNamePart[fileNamePart.length - 1];
try {
Files.write(Paths.get(fileNameWithPath), file.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return new ResultMsg(ResponseCodeEnum.SUCCESS.getIndex(), fileNameWithPath, "上传成功");
}
@PostMapping("/upload")
public ResultMsg algorithmFile(@RequestParam("file") MultipartFile file) {
String fileName = file.getOriginalFilename();
String[] fileNamePart = fileName.split("\\.");
String fileNameWithPath = filePath + UUID.randomUUID().toString(true) + "." + fileNamePart[fileNamePart.length -1];
try {
InputStream input = file.getInputStream();
FileOutputStream out = new FileOutputStream(new File(fileNameWithPath));
IOUtils.copy(input, out);
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return new ResultMsg(ResponseCodeEnum.SUCCESS.getIndex(), fileNameWithPath, "上传成功");
}
总结
错误代码中使用了,file.getBytes(),应该是该操作导致了内存溢出。具体区别和原因暂时没分析
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)