From 47cadfe1016d4e0d09d77858dc34f22ab1249c97 Mon Sep 17 00:00:00 2001 From: LeeHanEum Date: Mon, 12 Aug 2024 22:45:23 +0900 Subject: [PATCH] =?UTF-8?q?[SAMBAD-240]-refactor:=20contentLength=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/infrastructure/ObjectStorageFileUploader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/depromeet/sambad/moring/file/infrastructure/ObjectStorageFileUploader.java b/src/main/java/org/depromeet/sambad/moring/file/infrastructure/ObjectStorageFileUploader.java index 479174ae..ea0a1498 100644 --- a/src/main/java/org/depromeet/sambad/moring/file/infrastructure/ObjectStorageFileUploader.java +++ b/src/main/java/org/depromeet/sambad/moring/file/infrastructure/ObjectStorageFileUploader.java @@ -26,6 +26,7 @@ import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.util.IOUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -123,7 +124,10 @@ private HttpURLConnection getHttpURLConnection(String fileUrl) throws IOExceptio private ObjectMetadata setObjectMetaData(InputStream in, String contentType) throws IOException { ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentLength(in.available()); + byte[] byteArray = IOUtils.toByteArray(in); + long contentLength = byteArray.length; + in.close(); + objectMetadata.setContentLength(contentLength); objectMetadata.setContentType(contentType); return objectMetadata; }