Skip to content

Commit

Permalink
[FEAT] 상ëFIX¬ 마ì� 파일 업로드 시간 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gyurili committed Aug 5, 2024
1 parent 6907192 commit b7a9f71
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/viewmore/poksin/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -106,16 +108,20 @@ public void openRoom(String roomId) {
public ChatMessageEntity uploadFile(byte[] fileData, String fileName, String roomId, String username) {
String uniqueFileName = UUID.randomUUID().toString() + "-" + fileName;
try {
// S3에 파일 업로드
s3Client.putObject(new PutObjectRequest(bucketName, uniqueFileName, new ByteArrayInputStream(fileData), null));
String fileUrl = s3Client.getUrl(bucketName, uniqueFileName).toString();

// 한국 시간 설정
LocalDateTime timestamp = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();

ChatMessageEntity chatMessage = ChatMessageEntity.builder()
.fileUrl(fileUrl)
.fileName(fileName)
.roomId(roomId)
.sender(username)
.type(ChatMessageEntity.MessageType.FILE)
.timestamp(LocalDateTime.now())
.timestamp(timestamp)
.build();

return saveChatMessage(chatMessage);
Expand All @@ -124,4 +130,5 @@ public ChatMessageEntity uploadFile(byte[] fileData, String fileName, String roo
throw new RuntimeException("File upload failed: " + e.getMessage());
}
}

}

0 comments on commit b7a9f71

Please sign in to comment.