Skip to content

Commit

Permalink
임시
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1684 committed May 27, 2024
1 parent 003bc51 commit 4adf573
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
import java.util.List;
import java.util.UUID;

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -55,7 +50,7 @@ public List<MessageResponseDTO> getMyChatHistory(Long memberId) {
return messageRepository.findAllByMemberId(memberId).stream().map(MessageResponseDTO::new).toList();
}

public String changeImageBytesToUrl(byte[] imageBytes, String fileName, Long roomId) {
public String changeImageBytesToUrl(String imageCode, String fileName, Long roomId) {
String imageUrl = "";

String[] parts = fileName.split("\\.");
Expand All @@ -70,7 +65,8 @@ public String changeImageBytesToUrl(byte[] imageBytes, String fileName, Long roo
.build();

// Use RequestBody to create the request body from the byte array
RequestBody requestBody = RequestBody.fromBytes(imageBytes);
byte[] bytes = Base64.getDecoder().decode(imageCode);
RequestBody requestBody = RequestBody.fromBytes(bytes);

// Put the object in S3
s3Client.putObject(putObjectRequest, requestBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public MessageResponseDTO chat(SimpMessageHeaderAccessor accessor, @DestinationV
Meeting meeting = meetingService.findMeeting(roomId);

String imageUrl = "";
if (messageRequestDTO.getImageBytes() != null && messageRequestDTO.getFileName() != null) {
imageUrl = chatService.changeImageBytesToUrl(messageRequestDTO.getImageBytes(), messageRequestDTO.getFileName(), roomId);
if (messageRequestDTO.getImageCode() != null && messageRequestDTO.getFileName() != null) {
imageUrl = chatService.changeImageBytesToUrl(messageRequestDTO.getImageCode(), messageRequestDTO.getFileName(), roomId);
}

// 채팅 메시지 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@Builder
public class MessageRequestDTO {
private String message;
private byte[] imageBytes;
private String imageCode;
private String fileName;
}

0 comments on commit 4adf573

Please sign in to comment.