From 3e016ecc4f79e7527fe6909dae152c05d2839c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Sat, 1 Mar 2025 20:24:40 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"refactor(common-oss):=20S3=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E7=AE=80=E5=8C=96=E5=8E=BB=E6=8E=89?= =?UTF-8?q?byteinputstream"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a7f85b5824de208f5b692cf62a8f7caa16fea4ea. --- .../pigx/common/file/oss/service/OssTemplate.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 3b3cab058..4afc2fd8e 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,6 +28,7 @@ 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; @@ -35,6 +36,7 @@ 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.*; @@ -210,15 +212,21 @@ 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) { + String contextType) throws Exception { + // String fileName = getFileName(objectName); + byte[] bytes = IOUtils.toByteArray(stream); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(size); objectMetadata.setContentType(contextType); - return amazonS3.putObject(bucketName, objectName, stream, objectMetadata); + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); + // 上传 + return amazonS3.putObject(bucketName, objectName, byteArrayInputStream, objectMetadata); + } /**