From 7f2440ee38bf864b67bc6755828bf23f56b3b17f Mon Sep 17 00:00:00 2001 From: "SphinX[id]" <174735124@qq.com> Date: Sun, 30 Mar 2025 16:02:25 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8ByteArrayInputStream=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=87=8D=E7=BD=AE=E6=B5=81=E6=8A=A5=E9=94=99=E3=80=82?= =?UTF-8?q?=E8=BF=99=E9=87=8C=E6=98=AF=E5=90=A6=E8=A6=81=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E4=B8=8B=E6=99=AE=E9=80=9A=E6=96=87=E4=BB=B6=E5=92=8C=E5=A4=A7?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=86=E5=88=AB=E4=BD=BF=E7=94=A8=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SphinX[id] <174735124@qq.com> --- .../nop/integration/oss/OssFileServiceClient.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nop-integration/nop-integration-oss/src/main/java/io/nop/integration/oss/OssFileServiceClient.java b/nop-integration/nop-integration-oss/src/main/java/io/nop/integration/oss/OssFileServiceClient.java index 49ce99e39..c0e82cd41 100644 --- a/nop-integration/nop-integration-oss/src/main/java/io/nop/integration/oss/OssFileServiceClient.java +++ b/nop-integration/nop-integration-oss/src/main/java/io/nop/integration/oss/OssFileServiceClient.java @@ -24,10 +24,7 @@ import jakarta.ws.rs.core.MediaType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.ArrayList; import java.util.List; @@ -116,16 +113,22 @@ public class OssFileServiceClient implements IFileServiceClient { @Override public String uploadResource(IResourceReference file, String remotePath) { remotePath = normalizePath(remotePath); + InputStream is = file.getInputStream(); + ByteArrayInputStream bais = null; try { + byte[] fileBytes = IoHelper.readBytes(is); + bais = new ByteArrayInputStream(fileBytes); ObjectMetadata meta = new ObjectMetadata(); meta.setContentLength(file.length()); meta.setContentType(MediaType.APPLICATION_OCTET_STREAM); String bucketName = getBucketName(remotePath); makeBucket(bucketName); - client.putObject(bucketName, remotePath, is, meta); + client.putObject(bucketName, remotePath, bais, meta); + } catch (IOException e) { + throw new RuntimeException(e); } finally { - IoHelper.safeCloseObject(is); + IoHelper.safeCloseObject(bais); } return remotePath; -- Gitee