From eb8cab3f5af811f5b9e6a12b777262e3464f0cf1 Mon Sep 17 00:00:00 2001 From: old burden Date: Fri, 3 Apr 2026 14:24:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=85=BE=E8=AE=AF=E4=BA=91cos=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/common/utils/TencentCosUtil.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web-api/ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentCosUtil.java b/web-api/ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentCosUtil.java index 8dfad2e..1612c9e 100644 --- a/web-api/ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentCosUtil.java +++ b/web-api/ruoyi-common/src/main/java/com/ruoyi/common/utils/TencentCosUtil.java @@ -67,6 +67,14 @@ public class TencentCosUtil { try { InputStream inputStream = file.getInputStream(); ObjectMetadata objectMetadata = new ObjectMetadata(); + // 必须设置长度,否则底层 OkHttp 会告警「No content length specified…」并整段缓冲到内存,易 OOM + long contentLength = file.getSize(); + if (contentLength >= 0) { + objectMetadata.setContentLength(contentLength); + } + if (file.getContentType() != null && !file.getContentType().isEmpty()) { + objectMetadata.setContentType(file.getContentType()); + } PutObjectRequest putObjectRequest = new PutObjectRequest( bucketName, key,