From 5936548ccf20119289c1a5a9260f1f80d559eca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 13 Nov 2022 22:08:44 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=BC=93=E5=86=B2=E6=B5=81=20=E5=AF=BC=E8=87=B4=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98=20=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=E9=94=99=E8=AF=AF=E6=8F=90=E4=BA=A4=20#35fac6c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/common/oss/core/OssClient.java | 4 ++++ .../com/ruoyi/resource/service/impl/SysOssServiceImpl.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java index bbfb17ab..14271905 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java @@ -1,5 +1,6 @@ package com.ruoyi.common.oss.core; +import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; import com.amazonaws.ClientConfiguration; import com.amazonaws.HttpMethod; @@ -97,6 +98,9 @@ public class OssClient { } public UploadResult upload(InputStream inputStream, String path, String contentType) { + if (!(inputStream instanceof ByteArrayInputStream)) { + inputStream = new ByteArrayInputStream(IoUtil.readBytes(inputStream)); + } try { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(contentType); diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java index 54bd1e61..0c5161fe 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/com/ruoyi/resource/service/impl/SysOssServiceImpl.java @@ -114,7 +114,7 @@ public class SysOssServiceImpl implements ISysOssService { OssClient storage = OssFactory.instance(); UploadResult uploadResult; try { - uploadResult = storage.uploadSuffix(file.getInputStream(), suffix, file.getContentType()); + uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); } catch (IOException e) { throw new ServiceException(e.getMessage()); }