From 08f9b493e0f4f66eedf272f1c6c64978a64ff866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Mon, 30 Dec 2024 15:37:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(common-oss):=20S3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=AE=80=E5=8C=96=E5=8E=BB=E6=8E=89byteinput?= =?UTF-8?q?stream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/common/file/oss/service/OssTemplate.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/file/oss/service/OssTemplate.java b/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/file/oss/service/OssTemplate.java index 4afc2fd8e..3b3cab058 100755 --- a/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/file/oss/service/OssTemplate.java +++ b/pigx-common/pigx-common-oss/src/main/java/com/pig4cloud/pigx/common/file/oss/service/OssTemplate.java @@ -28,7 +28,6 @@ import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.*; -import com.amazonaws.util.IOUtils; import com.pig4cloud.pigx.common.file.core.FileProperties; import com.pig4cloud.pigx.common.file.core.FileTemplate; import lombok.Cleanup; @@ -36,7 +35,6 @@ import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.springframework.beans.factory.InitializingBean; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.net.URL; import java.util.*; @@ -212,21 +210,15 @@ public class OssTemplate implements InitializingBean, FileTemplate { * @param stream 文件流 * @param size 大小 * @param contextType 类型 - * @throws Exception * @see AWS * API Documentation */ public PutObjectResult putObject(String bucketName, String objectName, InputStream stream, long size, - String contextType) throws Exception { - // String fileName = getFileName(objectName); - byte[] bytes = IOUtils.toByteArray(stream); + String contextType) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(size); objectMetadata.setContentType(contextType); - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); - // 上传 - return amazonS3.putObject(bucketName, objectName, byteArrayInputStream, objectMetadata); - + return amazonS3.putObject(bucketName, objectName, stream, objectMetadata); } /**