diff --git a/BE/src/main/java/com/issuetracker/service/ImageService.java b/BE/src/main/java/com/issuetracker/service/ImageService.java index 1b0c594f3..c31efcc0a 100644 --- a/BE/src/main/java/com/issuetracker/service/ImageService.java +++ b/BE/src/main/java/com/issuetracker/service/ImageService.java @@ -8,6 +8,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata; import com.issuetracker.domain.image.Image; import com.issuetracker.domain.image.ImageRepository; +import com.issuetracker.web.dto.response.ImageResponseDTO; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -36,7 +37,7 @@ public ImageService(@Value("${cloud.aws.credentials.accessKey}") String accessKe this.imageRepository = imageRepository; } - public String upload(MultipartFile multipartFile) throws IOException { + public ImageResponseDTO upload(MultipartFile multipartFile) throws IOException { ObjectMetadata data = new ObjectMetadata(); data.setContentType(multipartFile.getContentType()); data.setContentLength(multipartFile.getSize()); @@ -50,7 +51,7 @@ public String upload(MultipartFile multipartFile) throws IOException { String imageName = getImageName(multipartFile); s3client.putObject(bucket, imageName, multipartFile.getInputStream(), data); Image image = saveImageUrl(defaultUrl + "/" + imageName); - return image.getImageUrl(); + return new ImageResponseDTO(image.getImageUrl()); } private String getImageName(MultipartFile multipartFile) { diff --git a/BE/src/main/java/com/issuetracker/web/ImageController.java b/BE/src/main/java/com/issuetracker/web/ImageController.java index 05a35a497..8b9520e4d 100644 --- a/BE/src/main/java/com/issuetracker/web/ImageController.java +++ b/BE/src/main/java/com/issuetracker/web/ImageController.java @@ -1,6 +1,7 @@ package com.issuetracker.web; import com.issuetracker.service.ImageService; +import com.issuetracker.web.dto.response.ImageResponseDTO; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -16,7 +17,7 @@ public class ImageController { private final ImageService imageService; @PostMapping("/api/images") - public String upload(@RequestParam("image") MultipartFile multipartFile) throws IOException { + public ImageResponseDTO upload(@RequestParam("image") MultipartFile multipartFile) throws IOException { return imageService.upload(multipartFile); } } diff --git a/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java b/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java new file mode 100644 index 000000000..75353f802 --- /dev/null +++ b/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java @@ -0,0 +1,11 @@ +package com.issuetracker.web.dto.response; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class ImageResponseDTO { + + private final String image; +}