From 22b411ed9809c3bf3b008751aeb5610899851b9f Mon Sep 17 00:00:00 2001 From: haozq <1611483981@qq.com> Date: Thu, 3 Jul 2025 19:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongodb/service/FileMongoServiceImpl.java | 12 +++++++----- .../src/main/resources/application-druid.yml | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bonus-business/src/main/java/com/bonus/business/mongodb/service/FileMongoServiceImpl.java b/bonus-business/src/main/java/com/bonus/business/mongodb/service/FileMongoServiceImpl.java index f05f2c9..5c56af3 100644 --- a/bonus-business/src/main/java/com/bonus/business/mongodb/service/FileMongoServiceImpl.java +++ b/bonus-business/src/main/java/com/bonus/business/mongodb/service/FileMongoServiceImpl.java @@ -165,8 +165,8 @@ public class FileMongoServiceImpl { * @throws Exception */ public FileExportVo saveBinaryFile(MultipartFile file) throws Exception { - String suffix = getFileSuffix(file); + InputStream input= file.getInputStream(); MongoFile mongoFile = mongoFileRepository.save( MongoFile.builder() .fileName(file.getOriginalFilename()) @@ -175,10 +175,11 @@ public class FileMongoServiceImpl { .contentType(file.getContentType()) .uploadDate(DateUtils.dateTimeNow()) .suffix(suffix) - .md5(Md5Util.getMd5(file.getInputStream())) + .md5(Md5Util.getMd5(input)) .build() ); - + //必须关闭 + input.close(); return new FileExportVo(mongoFile); } /** @@ -190,6 +191,7 @@ public class FileMongoServiceImpl { */ public FileExportVo saveGridFsFile(MultipartFile file) throws Exception { String suffix = getFileSuffix(file); + InputStream input= file.getInputStream(); String gridFsId = this.storeFileToGridFs(file.getInputStream(), file.getContentType()); MongoFile mongoFile = mongoTemplate.save( MongoFile.builder() @@ -198,11 +200,11 @@ public class FileMongoServiceImpl { .contentType(file.getContentType()) .uploadDate(DateUtils.dateTimeNow()) .suffix(suffix) - .md5(Md5Util.getMd5(file.getInputStream())) + .md5(Md5Util.getMd5(input)) .gridFsId(gridFsId) .build() ); - + input.close(); return new FileExportVo(mongoFile); } public FileExportVo saveBinaryFile(File file) throws Exception { diff --git a/bonus-business/src/main/resources/application-druid.yml b/bonus-business/src/main/resources/application-druid.yml index b987d16..d8d385e 100644 --- a/bonus-business/src/main/resources/application-druid.yml +++ b/bonus-business/src/main/resources/application-druid.yml @@ -9,7 +9,6 @@ spring: discovery: server-addr: 127.0.0.1:18848 namespace: robot - datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver