diff --git a/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/oss/http/OssEndpoint.java b/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/oss/http/OssEndpoint.java index f1e6d0b3c..8d85459e7 100755 --- a/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/oss/http/OssEndpoint.java +++ b/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/oss/http/OssEndpoint.java @@ -22,11 +22,13 @@ import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3ObjectSummary; import com.pig4cloud.pigx.common.oss.service.OssTemplate; import lombok.AllArgsConstructor; +import lombok.Cleanup; import lombok.SneakyThrows; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -84,7 +86,9 @@ public class OssEndpoint { @PostMapping("/object/{bucketName}") public S3Object createObject(@RequestBody MultipartFile object, @PathVariable String bucketName) { String name = object.getOriginalFilename(); - template.putObject(bucketName, name, object.getInputStream(), object.getSize(), object.getContentType()); + @Cleanup + InputStream inputStream = object.getInputStream(); + template.putObject(bucketName, name, inputStream, object.getSize(), object.getContentType()); return template.getObjectInfo(bucketName, name); } @@ -93,7 +97,9 @@ public class OssEndpoint { @PostMapping("/object/{bucketName}/{objectName}") public S3Object createObject(@RequestBody MultipartFile object, @PathVariable String bucketName, @PathVariable String objectName) { - template.putObject(bucketName, objectName, object.getInputStream(), object.getSize(), object.getContentType()); + @Cleanup + InputStream inputStream = object.getInputStream(); + template.putObject(bucketName, objectName, inputStream, object.getSize(), object.getContentType()); return template.getObjectInfo(bucketName, objectName); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysFileServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysFileServiceImpl.java index 549ceab01..db8407cb2 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysFileServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysFileServiceImpl.java @@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -67,13 +68,12 @@ public class SysFileServiceImpl extends ServiceImpl impl resultMap.put("fileName", fileName); resultMap.put("url", String.format("/admin/sys-file/%s/%s", ossProperties.getBucketName(), fileName)); - try { - minioTemplate.putObject(ossProperties.getBucketName(), fileName, file.getInputStream(), + try (InputStream inputStream = file.getInputStream()) { + minioTemplate.putObject(ossProperties.getBucketName(), fileName, inputStream, file.getContentType()); // 文件管理数据记录,收集管理追踪文件 fileLog(file, fileName); - } - catch (Exception e) { + } catch (Exception e) { log.error("上传失败", e); return R.failed(e.getLocalizedMessage()); }