diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java index 7dc41f623..b78ffebcd 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java @@ -457,7 +457,7 @@ public class MaterialBaseInfoApplicationService { throw new ServiceException("请上传xls或xlsx格式文件"); } - // 保存文件到临时目录 + // 流式写入临时文件,避免大文件 getBytes() 导致内存溢出和接口超时 String tmpDir = System.getProperty("java.io.tmpdir") + File.separator + "material_import"; File dir = new File(tmpDir); if (!dir.exists()) { @@ -465,8 +465,8 @@ public class MaterialBaseInfoApplicationService { } String tmpFileName = System.currentTimeMillis() + "_" + fileName; File tmpFile = new File(dir, tmpFileName); - try (FileOutputStream fos = new FileOutputStream(tmpFile)) { - fos.write(file.getBytes()); + try { + file.transferTo(tmpFile); } catch (Exception e) { throw new ServiceException("文件保存失败:" + e.getMessage()); }